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 Frog { | |
| constructor(name, gender, weight) { | |
| this.name = name | |
| this.gender = gender | |
| this.weight = weight | |
| } | |
| jump() { | |
| console.log('jumped') | |
| } |
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 Frog { | |
| constructor(name, gender) { | |
| this.name = name | |
| this.gender = gender | |
| } | |
| jump() { | |
| console.log('jumped') | |
| } | |
| } |
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 Button from '@material-ui/core/Button' | |
| import Menu from '@material-ui/core/Menu' | |
| import MenuItem from '@material-ui/core/MenuItem' | |
| import './styles.css' | |
| const items = [ | |
| { to: '/home', label: 'Home' }, | |
| { to: '/blog', label: 'Blog' }, | |
| { to: '/about', label: 'About' }, |
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
| function ControlPanel({ children, ...rest }) { | |
| const [opened, setOpened] = React.useState(false) | |
| const open = () => setOpened(true) | |
| const close = () => setOpened(false) | |
| const child = React.Children.toArray(children).map((child) => | |
| React.cloneElement(child, { opened, open, close, ...rest }), | |
| ) | |
| return <div>{child}</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
| function ControlPanel({ children, ...rest }) { | |
| const [opened, setOpened] = React.useState(false) | |
| const open = () => setOpened(true) | |
| const close = () => setOpened(false) | |
| return ( | |
| <div>{React.cloneElement(children, { opened, open, close, ...rest })}</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
| const DeactivatorInput = ({ | |
| component: Component = 'input', | |
| style, | |
| opened, | |
| open: openModal, | |
| close: closeModal, | |
| ...rest | |
| }) => ( | |
| <div> | |
| <Component |
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 useControlPanel from './useControlPanel' | |
| import ControlButton from './ControlButton' | |
| function useAuthValidator({ token }) { | |
| const [authenticated, setAuthenticated] = React.useState(null) | |
| React.useEffect(() => { | |
| if (isAuthed(token)) setAuthenticated(true) | |
| else setAuthenticated(false) | |
| }) |
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 useControlPanel from './useControlPanel' | |
| import ControlButton from './ControlButton' | |
| function useAuthValidator({ token }) { | |
| const [authenticated, setAuthenticated] = React.useState(null) | |
| React.useEffect(() => { | |
| if (isAuthed(token)) setAuthenticated(true) | |
| else setAuthenticated(false) | |
| }) |
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 ControlPanel from './ControlPanel' | |
| import ControlButton from './ControlButton' | |
| function AuthValidator({ token, render, ...rest }) { | |
| if (isAuthed(token)) { | |
| return render({ authenticated: true }) | |
| } | |
| return render({ authenticated: false }) | |
| } |
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' | |
| function useStuff() { | |
| const [data, setData] = React.useState({}) | |
| React.useEffect(() => { | |
| fetch('https://someapi.com/api/users/') | |
| .then((response) => setData(response.json())) | |
| .catch((err) => setData(err)) | |
| }, []) | |
| return { data, setData } |