Skip to content

Instantly share code, notes, and snippets.

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