Antoine P
Antoine P

Reputation: 29

React Popover not closing

I am new to React and trying to build a simple page using popovers (the page has n sections, each popover has different content, see projectContent array). I have 3 issues that must be related to the data being passed on from parent to child:

Upvotes: 0

Views: 1330

Answers (1)

ramirozap
ramirozap

Reputation: 1459

Your OverlayTrigger needs to pass a ref into your PopoverComponent, but PopoverComponent is not accepting refs, to solve this you can wrap your PopoverComponent with a forwardRef function and assign that ref to the root Popover:

const PopoverComponent = React.forwardRef(({ myData }, ref) => {
  return (
    <Popover title="Popover bottom" ref={ref}>
      <Popover.Title as="h3">Popover right</Popover.Title>
      <Popover.Content>
        {myData.title}
        {myData.type}
        <Button key={myData.id} onClick={() => document.body.click()}>
          Close
        </Button>
      </Popover.Content>
    </Popover>
  );
});

Upvotes: 2

Related Questions