Document how to put arrays and etc. in global state
See original GitHub issueI’m currently unsure how to deal with mutable objects in global state. Do you just do global.push(...); setGlobal(global)
? Would be helpful to have some documentation on this.
Issue Analytics
- State:
- Created 2 years ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
You Can Definitely Use Global Variables To Manage Global ...
Solution · Create a global state(which is technically a global variable) · Subscribe a component(s) to a created global state(this lets the global ......
Read more >React: store uploaded array into global variable?
I need to be able to send the array's values to other components/files, so I don't think having to call it like that...
Read more >An Introduction to Global State Management in React without ...
State can be stored in any data type, including arrays, booleans, ... Applications can include this global state for both functional and ...
Read more >React Global State with Context and Hooks | by Lorenzo Spyna
The hook useStore is similar to useState from React, and it returns an array with 3 entries: The first is the value of...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Good to know, thank you! Leaving this issue open because this is a common use-case that doesn’t seem to have any best practices listed
Unnecessary hostility. Also, the
global.push
was referencing a theoretical variable namedglobal
, not part of the library’s API.For future reference, the way to update arrays is global state is to call
setGlobal
with a new object, to push to arrays it’s[...oldArray, newObject]
. To removefilter
can be used, and so on.