Created
August 9, 2023 09:06
-
-
Save yuheiy/330f3068be75f38e2469997819786344 to your computer and use it in GitHub Desktop.
This file contains 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
function HooksSeparator<T>({ | |
setup, | |
children, | |
}: { | |
setup: () => T; | |
children: (prop: T) => ReactNode; | |
}) { | |
return children(setup()); | |
} | |
render( | |
<HooksSeparator | |
setup={() => { | |
const [isOpen, setOpen] = useState(false); | |
return { | |
isOpen, | |
setOpen, | |
}; | |
}} | |
> | |
{({ isOpen, setOpen }) => ( | |
<> | |
<button type="button" onClick={() => setOpen(true)}> | |
open | |
</button> | |
<Popover isOpen={isOpen} onOpenChange={setOpen}> | |
content | |
</Popover> | |
</> | |
)} | |
</HooksSeparator>, | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment