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 { makeStyles } from '@material-ui/core'; | |
| import TextField from '@material-ui/core/TextField'; | |
| import Button from '@material-ui/core/Button'; | |
| import { useForm, Controller } from 'react-hook-form'; | |
| const useStyles = makeStyles(theme => ({ | |
| root: { | |
| display: 'flex', | |
| flexDirection: 'column', |
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 { render } from "@testing-library/react"; | |
| import { Provider } from "react-redux"; | |
| import { applyMiddleware, createStore } from "redux"; | |
| import { Router } from "react-router-dom"; | |
| import thunk from "redux-thunk"; | |
| import { createMemoryHistory } from "history"; | |
| import reducer from "../store/reducers/index"; | |
| const customRender = (ui { actions = [], route = "/" } = {}) => { |
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 { render, screen } from '@testing-library/react'; | |
| import App from './App'; | |
| test('renders learn react link', () => { | |
| render(<App />); | |
| const linkElement = screen.getByText(/learn react/i); | |
| expect(linkElement).toBeInTheDocument(); | |
| }); |
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
| // jest-dom adds custom jest matchers for asserting on DOM nodes. | |
| // allows you to do things like: | |
| // expect(element).toHaveTextContent(/react/i) | |
| // learn more: https://github.com/testing-library/jest-dom | |
| import '@testing-library/jest-dom'; |
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, { useState } from 'react'; | |
| import { makeStyles } from '@material-ui/core'; | |
| import TextField from '@material-ui/core/TextField'; | |
| import Button from '@material-ui/core/Button'; | |
| const useStyles = makeStyles(theme => ({ | |
| root: { | |
| display: 'flex', | |
| flexDirection: 'column', | |
| justifyContent: 'center', |
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 { useState } from 'react'; | |
| import Button from '@material-ui/core/Button'; | |
| import ModalDialog from './ModalDialog'; | |
| const App = () => { | |
| // declare a new state variable for modal open | |
| const [open, setOpen] = useState(false); | |
| // function to handle modal open | |
| const handleOpen = () => { |
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 Dialog from '@material-ui/core/Dialog'; | |
| import Form from './Form'; | |
| const ModalDialog = ({ open, handleClose }) => { | |
| return ( | |
| // props received from App.js | |
| <Dialog open={open} onClose={handleClose}> | |
| // form to be created | |
| <Form handleClose={handleClose} /> |
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, { useState } from 'react'; | |
| import Counter from './Counter'; | |
| import { ErrorBoundary } from 'react-error-boundary'; | |
| const ErrorFallback = ({ error, resetErrorBoundary }) => { | |
| return ( | |
| <div role="alert"> | |
| <p>Something went wrong:</p> | |
| <pre>{error.message}</pre> | |
| <button onClick={resetErrorBoundary}>Try again</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
| class ErrorBoundary extends React.Component { | |
| constructor(props) { | |
| super(props); | |
| this.state = { hasError: false }; | |
| } | |
| static getDerivedStateFromError(error) { | |
| // Update state so the next render will show the fallback UI. | |
| return { hasError: true }; | |
| } |
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, { useState } from 'react'; | |
| import Counter from './Counter'; | |
| const App = () => { | |
| const [count, setCount] = useState(0); | |
| return ( | |
| <div className="App"> | |
| <Counter count={count} setCount={setCount} /> | |
| </div> |