Skip to content

Instantly share code, notes, and snippets.

@yuheiy
Created August 9, 2023 09:06
Show Gist options
  • Save yuheiy/330f3068be75f38e2469997819786344 to your computer and use it in GitHub Desktop.
Save yuheiy/330f3068be75f38e2469997819786344 to your computer and use it in GitHub Desktop.
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