Questions tagged [global-state]
66 questions
2
votes
0 answers
How to make global alert in React?
I'm trying to create a global alert in my React application that shows up at the top of the screen and every component could use. I have the component GlobalAlert that's used in App.
The problem arises when I'm trying to pass GlobalAlert's setAlert…
user11126091
2
votes
3 answers
Why when using setState(...) is the console.log null?
Why when I console.log(data) is does it log the data but when I try and log the item set by set state its null? I don't understand is it because it doesn't have time to update before console logging?
const [currentUser, setCurrentUser] =…

lukeet
- 461
- 1
- 4
- 22
2
votes
3 answers
Why isn't a database considered a form of global state?
I have a general gut feeling about the difference but I'm unable to pinpoint exactly what makes a database different from global state.
With a naive definition of "global state", a database is generally at least application-global. You could…

Davy8
- 30,868
- 25
- 115
- 173
2
votes
1 answer
How to avoid the global state in Swift
I been reading about avoiding the mutable state, and how the singleton pattern is bad for having a global state.
I see few answers about Dependency injection http://www.objc.io/issue-13/singletons.html, but I can not find how to solve this basic…

Memo Anaya Magallon
- 21
- 1
2
votes
1 answer
Why is global state bad?
I had a talk with someone on the #ruby-lang channel the other day about @@class_variables. It all started when a user asked what's the best way to keep track of connected users to his server (I slightly simplified it, but that's the gist of it).
So,…

omninonsense
- 6,644
- 9
- 45
- 66
2
votes
0 answers
PHP global state acceptable for runtime information like class metadata?
I'm struggling with using global state to store runtime information about class metadata in PHP. As global state is considered "bad" because of the obvious reasons I would like to avoid it as much as I can. Though, I still don't know in which…

user2624343
- 21
- 2
1
vote
0 answers
Reducing mutable shared state
So I'm going through a ray tracing tutorial in an attempt to stretch my F# legs. Since the tutorial is written in C++, it a rather fun challenge to figure out how to apply the concepts in a functional manner. I'd like to write everything in as…

Ken Wayne VanderLinde
- 18,915
- 3
- 47
- 72
1
vote
0 answers
Large Project Architecture with React and Zustand Tips. One Store vs Multiple Stores? (Diagrams)
I'm currently working on a 3D orthodontic treatment planning software for doctors. The app has one big global store that is split into slices. I also have non-view-specific business logic on the client that is stored in a separate folder (plain…

ellis
- 181
- 10
1
vote
1 answer
How to trigger a state like setState with MobX, mobx-react-lite?
I want to carry to states into the global state with mobx. I'm struggling to create a global state in mobx. Also, I would like to mention that I'm using mobx-react-lite library.
Here is the link to codesanbox. If you open the commands, you will be…

ffcabbar
- 351
- 1
- 3
- 18
1
vote
2 answers
I want to use axios's return to global state ,but Promise { }
const Board = () => {
...
const {selected} = useSelector(state => state.board);
// In Redux reducer ->
// const initialState = {
// selected : {}
// }
const getOnePost = async (id) => {
try {
const…

hjch0211
- 13
- 2
1
vote
3 answers
next.js how to manage global state with context in across multiple layouts
I'm using two layouts in next.js in accordance with per page layout structure.
One layout for unauthenticated pages
Another one for authenticated pages
in _app.js
import GlobalContext from "../utils/GlobalContext";
....
return getLayout(
…

Kasun
- 679
- 1
- 7
- 21
1
vote
1 answer
NextJS: Pass string via context from input into getStaticProps
I´m new to NextJS and React at all so I ask for your forgiveness.
I want to know how to pass an users written text from an input field (inside of Header) into the getStaticProbs function of a specific page via the react context api.
I tried the…

Ydonut13
- 47
- 1
- 11
1
vote
1 answer
ModuleNotFoundError: No module named 'global_state'
For the small project I'm working on, I have to use the package easygui with import easygui. I believe I installed it correctly, but now I'm getting the error:
ModuleNotFoundError: No module named 'global_state'
From my understanding, it has…

James Marlin
- 13
- 1
- 7
1
vote
1 answer
Why does the state update but I can't access it via hooks in React?
I'm having trouble accessing my updated global state in react via hooks. I created custom hooks to get away from reducers and anything redux because I'm not a fan of it. Everything is working well but i cannot access my state.
Here is how the global…

Anthony Gayflor
- 17
- 5
1
vote
1 answer
ReactN is giving me undefined then I use "useGlobal" and try to get the state
When I use the reactn library ( that manage and facilitate hooks) to get my initial global state that I assigned with setGlobal its not setting anything. When I try to get It says undefined.
I have used this library before and it usually is just a…

bluefang05
- 21
- 2