Skip to content

Instantly share code, notes, and snippets.

@jsmanifest
Created April 2, 2020 03:16
Show Gist options
  • Save jsmanifest/22e138b0a42ca0efab20c5f43f02cd21 to your computer and use it in GitHub Desktop.
Save jsmanifest/22e138b0a42ca0efab20c5f43f02cd21 to your computer and use it in GitHub Desktop.
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)
})
return { authenticated }
}
function App() {
const { authenticated } = useAuthValidator('abc123')
const { Container, width, height, controls } = useControlPanel({
authenticated,
})
return (
<Container>
<div style={{ width, height }}>
{controls.map((options) =>
options.render ? (
<ControlButton
render={({ Component }) => <Component {...options} />}
/>
) : (
<ControlButton {...options} />
),
)}
</div>
</Container>
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment