react-new-window icon indicating copy to clipboard operation
react-new-window copied to clipboard

Child windows doesn't work when parent unmount (change route)

Open Mert18 opened this issue 3 years ago • 2 comments

So I keep my window open on route change via closeOnUnmount prop. But after changing the route, functions are not working as expected in the children. Please see below:

const Children = () => {
  const [count, setCount] = useState(0);

  const handleClick = () => {
    setCount(count + 1);
  };

  return (
    <div>
      <p>Count {count}</p>
      <button onClick={handleClick}>Increment</button>
    </div>
  );
};
const Parent = () => {
  return (
      <NewWindow closeOnUnmount={false}>
        <Children />
      </NewWindow>
  );
};

After changing the route, count stays where I left and handleClick function does not work anymore. Do you have any idea how can I find a way to avoid this behavior. Thanks in advance.

Mert18 avatar Jun 24 '22 13:06 Mert18

I was able to reproduce the issue. Thank you for well describing it. At first glance, it seems that unmount the page cause any child to get unmounted too. That might explain why the popup doesn't work.

We might need to figure out a way to make it work without crossing the line into a bad pattern.

rmariuzzo avatar Nov 27 '22 03:11 rmariuzzo

I have met the same problem. does author fix it now? or find some ways to handle now?

nigel201611 avatar May 16 '24 01:05 nigel201611