Skip to content

Instantly share code, notes, and snippets.

@jsmanifest
Created April 2, 2020 03:17
Show Gist options
  • Save jsmanifest/010e230343fbb7661a0baddf4c893414 to your computer and use it in GitHub Desktop.
Save jsmanifest/010e230343fbb7661a0baddf4c893414 to your computer and use it in GitHub Desktop.
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>
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment