Created
April 2, 2020 03:16
-
-
Save jsmanifest/22e138b0a42ca0efab20c5f43f02cd21 to your computer and use it in GitHub Desktop.
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) | |
}) | |
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