Questions tagged [react-state-management]

637 questions
3
votes
3 answers

How do I pass things between components on the same level?

I've got a React app of the form: I want to be able to update some state values of by clicking on elements in . I…
cjm2671
  • 18,348
  • 31
  • 102
  • 161
3
votes
2 answers

Which is the way React unmounts child components?

i'm kinda newbie on React but when I was learning about componentWillUnmount() method I found a behavior I can't understand. Consider this script (here's the fiddle -> https://jsfiddle.net/ockhamsblade/4zf5tq2h/37/): let myArray =…
3
votes
2 answers

React: Error referencing a function within state

the problem seems simple, but I can't figure out how to solve it: Add-Button declared within the render-Function works just fine Add-Button declared within the state itself doesn't work. As the code already mentions, it will throw the "TypeError:…
trynalearn
  • 39
  • 3
3
votes
1 answer

What exactly is prevState in a functional component's setState?

Returning the (changed) previous state within a setState that one gets from the useState hook doesn't seem to alter state. Run the following straight forward snippet function App(){ const [state, setState] = React.useState([{x: 0}]) function…
3
votes
2 answers

Two way data binding in React with Hooks

I am building an application with React where two components should be able to change state of each other: Component A -> Component B Component B -> Component A The Component A is a set of buttons and the Component B is an input element. I managed…
Eric Rovell
  • 393
  • 1
  • 6
  • 15
3
votes
1 answer

Getting value of input causing flickering in React

I am attempting to track the value of two login input fields by getting their value on change and storing this value in the local state so that when the user submits the login, I can just get the current values from the state. However, this results…
mlz7
  • 2,067
  • 3
  • 27
  • 51
3
votes
4 answers

useReducer returning undefined rather then array of objects

To get stuck in with react hooks I decided to try and make snake and use useReducer/useContext state management. Right now I'm blocked where I want a directional keypress to change the state of the active tile. In useReducer this seems to receive…
pyan
  • 865
  • 2
  • 12
  • 23
3
votes
1 answer

Re-rendering only updated elements on react form

I want to achieve a dynamically built form with controlled components that scale well. The problem I'm having is updating the state is causing the entire form to re-render (or something expensive?) causing epic type lag. // Generate some example…
MeatPopsicle
  • 832
  • 13
  • 28
3
votes
2 answers

Component renders twice on async React context update

I have React application which manages state using React context. I've created simple counter incrementation reproduction. There are two contexts. One for storing state, and the second one for dispatching. It's a pattern taken from this article. The…
3
votes
3 answers

How to update state of a component which uses two context consumers

I have a class component which uses two contexts with the value generated from API calls to a REST API. What I want to do is get the context values and use them to update my component state. I'm passing the context values like so …
Octavian
  • 623
  • 2
  • 6
  • 17
3
votes
1 answer

If a function updates state and another function accesses the state immediately afterwards, would it result in a race condition?

I have two components, one that uploads a file, and another that is a form that can be submitted. The uploader has a callback for when the upload is complete and the form has a callback for when the form is submitted. My goal is to make a request to…
3
votes
3 answers

React setState for multi level state object

I'm trying to update my state object which contains multiple levels. See this example https://codesandbox.io/s/oq9kp9vy5y. The problem is, that the values in the render method, does not update ... only the first one. Can I force an update or is…
3
votes
1 answer

React Context initial state is being mutated - JavaScript / React

I am making a guide me section. What this guide me section does - displays an array of processes. Within each process is an array of steps, within each step is an array of options. The user selects an option from one of the steps, it takes them to…
3
votes
1 answer

Setting the defultValue of TextField component of Material UI in React

I am developing a React JS application. What I am doing now is I am fetching data asynchronously from the server and render the values in the TextField. I know how to do it and my approach is working as well. But, I just do not like my current…
Wai Yan Hein
  • 13,651
  • 35
  • 180
  • 372
2
votes
1 answer

How to use Context API in Next JS 13 with server-side components?

Is it possible in Next JS 13 to fetch data on the server but then propagate it to Context API? In my case, I want to fetch user information via token on the server, but then pass it to Context API since I may use user data somewhere else in the app.…