From c52a8843e839287c5103427e8d0d368279b9203a Mon Sep 17 00:00:00 2001 From: p-sw Date: Sun, 30 Jun 2024 22:44:14 +0900 Subject: [PATCH] feat(Popover): make opened prop update internal opened state in realtime --- packages/react/components/Popover.tsx | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/packages/react/components/Popover.tsx b/packages/react/components/Popover.tsx index 80de2b6..15a7531 100644 --- a/packages/react/components/Popover.tsx +++ b/packages/react/components/Popover.tsx @@ -26,14 +26,20 @@ interface PopoverProps extends AsChild { } const Popover = ({ children, opened, asChild }: PopoverProps) => { - const state = React.useState({ + const [state, setState] = React.useState({ opened: opened ?? false, }); + useEffect(() => { + if (opened !== undefined) { + setState((p) => ({ ...p, opened: opened })); + } + }, [opened]); + const Comp = asChild ? Slot : "div"; return ( - + {children} );