Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Mert18 opened this issue Jun 24, 2022 · 2 comments
Open

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

Mert18 opened this issue Jun 24, 2022 · 2 comments

Comments

@Mert18
Copy link

Mert18 commented Jun 24, 2022

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.

@rmariuzzo
Copy link
Owner

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 rmariuzzo changed the title Functions won't work after route change Child windows doesn't work when parent unmount (change route) Nov 27, 2022
@nigel201611
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants