Questions tagged [global-state]
66 questions
0
votes
0 answers
How to organise Modular Project with useState, global Variables, global Functions
so i have a App.js, a Module with buttons, Class with functions, Global variables and state.
How do i manage all that and make State from App.js accessible in Functions Class?

General Warmonger
- 11
- 4
0
votes
0 answers
React global state with hooks
I am trying to create a global state variable with hooks. My simple test code works perfectly, but the browser gives me warning:
Warning: Functions are not valid as a React child. This may happen if you return a Component instead of …

Kaj Risberg
- 617
- 9
- 15
0
votes
1 answer
Is there a way to make a custom hook modify a global state on any call?
This is my custom hook:
function useFetch({url = '', method = 'get', body}) {
const [data, setData] = useState(null);
useEffect(() => {
try {
(async () => {
const data = await fetch[method](url, body);
setData(data);
…

Guido Glielmi
- 73
- 1
- 5
0
votes
1 answer
managing global state with parameterization (without singleton) but with a templated class
I am writing a small pub/sub application in c++14/17 for practice and self-learning. I say 14/17 because the only feature of c++17 I have used for this project so far has been the std::scoped_lock.
In this toy application, the publishers and…

Sam Hammamy
- 10,819
- 10
- 56
- 94
0
votes
1 answer
How to reassign/replace a value of an array by index if its in a global state
I have a global state that is an array [1,0, null,1,0....] I want to access the array by index let's say index 5 I want just to replace that value with 1 I have the array and I have the index but I don't know how to reassign and update the…

Edd
- 3
- 2
0
votes
0 answers
setLoggedIn is not a function react
Okay I'm trying to use global states to store if an user is logged in or not. To do so, I've created a Context file as follows:
import { createContext } from "react";
export const LoginContext= createContext({})
I also have my App.jsx:
import…

Laura
- 15
- 6
0
votes
1 answer
How to update/edit with Context API
I know its possible to ADD and DELETE a file through the context API, but how would you edit one?
For example: This is the DELETE function with Global Context
case "DELETE_TRANSACTION":
return {
...state,
transactions:…

Toan Lam
- 109
- 2
- 12
0
votes
0 answers
Issue persisting Global State ReactJS
I am working on a project where I have implemented global state using what's available within ReactJS, no third party library is being used.
When I set the global state, I then also add it to the local storage so if the browser reloads, the idea is…

Boardy
- 35,417
- 104
- 256
- 447
0
votes
1 answer
React Hooks - useState for global state management
I know there is now the Context API which should be used for global app state management.
But I am wondering, is there anything wrong (or not optimal) with managing the global state of the app using useState and passing into props like…

Jellohouse
- 165
- 3
- 12
0
votes
2 answers
array reducer is concatenating. not adding to sum. context with react
component:
const { transactions } = useContext(GlobalContext);
const amounts = transactions.map((transaction) => transaction.amount);
const total = amounts.reduce((acc, item) => (acc += item), 0).toFixed(2);
the total const is throwing an…

Toan Lam
- 109
- 2
- 12
0
votes
1 answer
Redux state change but the component don't re render whene I back to the screen
I have two screens, A and B. both of them uses the same global state
{this.props.profleInfos.Points}
using this :
const mapStateToProps = (state) => {
return {
folder: state.account.folder,
…

zedArt
- 487
- 1
- 10
- 27
0
votes
1 answer
Context API bringing state up to higher component
I'm trying to get my nav bar to change depending on which page the app is on without having to create individual nav components for each page. I want the nav bar to change once the user goes to a new 'projects' page. The way I would do this is to…

albert_anthony6
- 594
- 2
- 9
- 30
0
votes
1 answer
Best design pattern to pass needed variable to all code without
Basically, I have a boolean which is used by like 20% of all my classes on a large API project. Everything, from utility methods to larger classes, uses it. I can set the state (which will not change) on the program start, but don't know the "best"…

Big_Bad_E
- 947
- 1
- 12
- 23
0
votes
1 answer
React global state via props
Im using a shared global state as the following:
interface DashboardProps extends React.Props {
globalState? : GlobalState
}
export class Dashboard extends React.Component{
}
In AppLayout i call it:

SexyMF
- 10,657
- 33
- 102
- 206
0
votes
1 answer
Cannot get value from Global State(Redux)
I am having trouble creating this shared component in my project.
This is simplified version of its code:
import React from 'react';
import { View } from 'react-native';
import { connect } from 'react-redux';
function mapStateToProps(state) {
…

Mindaugas
- 1,173
- 5
- 15
- 31