๐
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { useEffect, useState } from "react"; | |
| const isEnabledMocking = process.env.NEXT_PUBLIC_ENABLE_API_MOCKING === "true"; | |
| export default function useMswMock() { | |
| const [shouldRender, setShouldRender] = useState(!isEnabledMocking); | |
| useEffect(() => { | |
| async function initMocks() { | |
| const { worker } = await import("./browser"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import type { NextApiRequest, NextApiResponse } from "next"; | |
| import axios from "axios"; | |
| export default async function handler(req: NextApiRequest, res: NextApiResponse) { | |
| if (req.method !== "POST") { | |
| return res.status(405).json({ message: "Method not allowed" }); | |
| } | |
| try { | |
| const formData = new FormData(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import React from "react"; | |
| import PropTypes from "prop-types"; | |
| const Filter = ({ filter, handleFilterChange }) => ( | |
| <div> | |
| <h3>Search Available Books</h3> | |
| <input value={filter} type="text" onChange={handleFilterChange} /> | |
| </div> | |
| ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import React from "react"; | |
| import { connect } from "react-redux"; | |
| import { ADDBOOK } from "../actions/index"; | |
| import PropTypes from "prop-types"; | |
| const mapDispatchToProps = dispatch => ({ | |
| createBook: book => dispatch(ADDBOOK(book)) | |
| }); | |
| const BookForm = ({ createBook }) => { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import React from "react"; | |
| import { CREATEBOOK, REMOVEBOOK, FILTER } from "../actions/index"; | |
| import { connect } from "react-redux"; | |
| import PropTypes from "prop-types"; | |
| import Filter from "../components/filterBook"; | |
| import Book from "../components/book"; | |
| const mapStateToProps = state => ({ | |
| books: state.book, | |
| filter: state.filter |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import React from "react"; | |
| import PropTypes from "prop-types"; | |
| const Book = ({ bk, handleRemove }) => ( | |
| <div style={{ border: "1px solid green", padding: "5px" }}> | |
| <h2>{bk.name}</h2> | |
| <h3>{bk.author}</h3> | |
| <button type="button" onClick={() => handleRemove(bk)}> | |
| Delete | |
| </button> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import React from "react"; | |
| import ReactDOM from "react-dom"; | |
| import { Provider } from "react-redux"; | |
| import { createStore } from "redux"; | |
| import rootReducer from "./reducers/index"; | |
| import App from "./components/App"; | |
| const store = createStore(rootReducer); | |
| ReactDOM.render( |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import book from "./book"; | |
| import filter from "./filter"; | |
| import { combineReducers } from "redux"; | |
| const rootReducer = combineReducers({ | |
| book, | |
| filter | |
| }); | |
| export default rootReducer; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const filter = (state = "", action) => { | |
| switch (action.type) { | |
| case "FILTER": | |
| return action.filter; | |
| default: | |
| return state; | |
| } | |
| }; | |
| export default filter; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const initialState = [ | |
| { | |
| name: "The Intelligent Investor", | |
| author: "Ben Graham" | |
| }, | |
| { | |
| name: "Harry Potter and the Philosopher's Stone", | |
| author: "J. K. Rowling" | |
| } | |
| ]; |
NewerOlder