Questions tagged [react-state-management]
637 questions
2
votes
1 answer
React Context Consumer not changing reactively or rerendering
I have an odd situation where a state variable is updating successfully in one component but not in the other. I'm successfully changing the state, because I can see it reflected in the component where I'm triggering a dispatch. But in another…

crevulus
- 1,658
- 12
- 42
2
votes
2 answers
How to manage function component state in NextJS?
I wanna to access a state variable of component 1 in component 2, they are "brothers" components. How can I do this? Only 1 state variable. I'm using nextjs with styled-components and typescript. Also my project have atomic design structure.
I wanna…

andreddev
- 23
- 1
- 5
2
votes
2 answers
cart count is not getting updated properly
screeen record of the issue: https://streamable.com/ofn42v
it is working fine in local but once deployed to production(vercel), it is not working. i have tried sooo many different things like having a separate state in cart, useEffect with…

RGog
- 96
- 12
2
votes
4 answers
React useEffect doesn't dispatch the redux action after page refresh
I'm trying to render the data from the following object of data which is coming from an API.
{
"code": 0,
"c": "verified",
"d": "verified",
"leaseInfo": {
"infoId": 6
},
"cpfPrice": "500.00",
"carCurrentLocation":…

Vidarshan Rathnayake
- 484
- 1
- 10
- 20
2
votes
1 answer
How to correctly handle loading state in redux toolkit crud
I want to know the best way for handling the loading state in redux-toolkit.
I have this slice and here I can create a post, delete a post, get all posts.
And as I think, for all these operations I need to handle a loading state. So when the user…

Rostyk
- 939
- 3
- 13
- 32
2
votes
0 answers
How do I deal with two useEffect hooks where one useEffect dependency is affecting another useEffect dependency?
So I'm working on a website that has infinite scrolling and sorting/filtering. The issue is that when the sortBy method is being changed, I need to reset the offset for the pagination for the infinite scrolling page.
Here's the code for the…

Kenneth Lee
- 21
- 1
2
votes
5 answers
In ReactJS How to save Child State in Parent state on destroying child?
I have a parent Component and two child Component as below:
ParentComponent:
import React, { useState } from "react";
import { Child1Comp } from "./Child1Comp";
import { Child2Comp } from "./Child2Comp";
export function ParentComp() {
const…

mehdi parastar
- 737
- 4
- 13
- 29
2
votes
2 answers
React state is empty after setting
I have simple nextjs app where i want to save and print state to fetchData
This is my code
const Room = () => {
const router = useRouter();
const [fetchData, setFetchData] = useState("");
useEffect(() => {
if (router.asPath !==…

Michaelo
- 579
- 1
- 5
- 13
2
votes
4 answers
React add and remove a component on button click
I'm new to React. Here I'm trying to add/remove a 'Timer' component on click of +/- button. It works fine on click of '+', but not on '-'. I was of the opinion that every time I set a state, the component re-renders. But here it doesn't render on…

Deva44
- 93
- 2
- 9
2
votes
1 answer
MobX ReactJS AntD updates won't re-render
So I'm trying change some table data within my AntD Table using ReactJS and MobX. The data in my MobX observable changes, but the table doesn't re-render an update until I say.... resize the page and the table re-renders. I've recreated my issue on…

elisciandrello
- 107
- 10
2
votes
1 answer
React Recoil selector not triggering its get when the atom state updates to a previous value
I've started learning React and Recoil by doing a quick project of my own. A single page website that has buttons where each button, in short, make a REST call and a table is created with the data returned.
When a button is clicked, it updates an…

worm
- 21
- 1
- 3
2
votes
1 answer
Unable to set state of TextField to undefined using React hook
I would like to have the initial state for a date TextField be set to undefined until the user has selected a date, and then allow the user to easily reset the date back to undefined.
In the following code, the Reset button will properly reset…

phoenix
- 7,988
- 6
- 39
- 45
2
votes
2 answers
Why is my state array resetting to empty?
For some reason, only the last element of my messages state array is rendering. Whenever I call addMessage and print the current state of messages, an empty array always prints out. After I push the new message to the state array, the array prints…

asdfcoder
- 123
- 1
- 9
2
votes
2 answers
React redux updating single property with different dispatch vs updating whole object
I have a below redux state
state:{
prop1:
prop2:
prop3:
}
Each property value comes from a dropdown element on the UI.
What would be the best way to update the state when onChange of any of these inputs. Update the whole object when any of…

dev0864
- 465
- 2
- 7
- 17
2
votes
2 answers
In React, how do I name a field of my form that is part of an array?
I'm building a React 16.13.0 application. In my form, I want to submit data (an address) as part of an array, so I set up my state like so ...
constructor(props) {
super(props);
this.state = {
countries: [],
provinces: [],
…

Dave
- 15,639
- 133
- 442
- 830