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

createGlobalState could not share state in the child mount/unmount component. #1259

Open
nghiepdev opened this issue Jun 3, 2020 · 3 comments

Comments

@nghiepdev
Copy link

What is the current behavior?
When the child component unmount global state is lost.

Steps to reproduce it and if possible a minimal demo of the problem
https://codesandbox.io/s/bug-react-use-create-global-state-9tykc

  1. Click the plus button
  2. Click the toggle button
  3. Click the plus button

ezgif-1-d676e02ee571

What is the expected behavior?
The child component should share the same state.

A little about versions:

  • OS: OSX
  • Browser (vendor and version): Chrome
  • React: 16.13.1
  • react-use: 15.1.1
@MrHuangJser
Copy link
Contributor

MrHuangJser commented Jun 4, 2020

em... I saw your example , you use the setValue like this setValue(val=>newVal), the current version does not support this approach, you can use like this

`
const [value,setValue] = useGlobalValue();
setValue(value+1)
`

@MrHuangJser
Copy link
Contributor

i'll support in next pr

@nspaeth
Copy link

nspaeth commented Jun 20, 2020

Can you see if #1021 fixes this?

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

No branches or pull requests

3 participants