Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Document how to put arrays and etc. in global state

See original GitHub issue

I’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:closed
  • Created 2 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

LoganDarkcommented, Jun 28, 2021

The call to setGlobal is what triggers the re-render. 😃

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

LoganDarkcommented, Sep 24, 2021

This is not an issue and should be closed. Nowhere in the documentation there is any global.push line, while it is obvious that you should interact with the global object only through the dedicated methods.

Unnecessary hostility. Also, the global.push was referencing a theoretical variable named global, 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 remove filter can be used, and so on.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Document how to put arrays and etc. in global state.
Read more >
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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Post

No results found

github_iconTop Related Hashnode Post

No results found