Skip to content

Instantly share code, notes, and snippets.

class Frog {
constructor(name, gender, weight) {
this.name = name
this.gender = gender
this.weight = weight
}
jump() {
console.log('jumped')
}
class Frog {
constructor(name, gender) {
this.name = name
this.gender = gender
}
jump() {
console.log('jumped')
}
}
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' },
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>
}
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>
)
}
const DeactivatorInput = ({
component: Component = 'input',
style,
opened,
open: openModal,
close: closeModal,
...rest
}) => (
<div>
<Component
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)
})
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)
})
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 })
}
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 }