Questions tagged [react-state-management]

447 questions
48
votes
8 answers

How to pass state back to parent in React?

I have a form that has a submit button. That form calls a function onclick that sets the state of something from false to true. I then want to pass this state back to the parent so that if it is true it renders componentA but if it is false it…
The worm
  • 3,578
  • 10
  • 26
  • 44
16
votes
2 answers

Managing user's global state on next.js application

I am coming from the world of SPA's and REST/GraphQl API's. Now I am building personal project with Next.js library for SSR(Server Side Rendered) React App. Since I used Redux in all of my single page Apps, I'm now wondering how should I manage user…
7
votes
4 answers

How to set zustand state in a class component

I am working on a site that has a piece a global state stored in a file using zustand. I need to be able to set that state in a class component. I am able to set the state in a functional component using hooks but I'm wondering if there is a way to…
7
votes
6 answers

using Material-ui checkboxes with the reactjs and redux

I want to display the selected checkbox items, for which I'm using material-ui checkbox. Right now I'm only able to display the items with checkboxes, but I am not able to display the selected items. I know it is easy but I'm new to reactjs and…
devanya
  • 177
  • 1
  • 1
  • 10
6
votes
1 answer

How to reduce react context hell?

I have inherited a codebase where the previous owner has made extensive use of React.Context. This has resulted in what might be described as "context hell"
spinners
  • 2,021
  • 1
  • 17
  • 31
6
votes
1 answer

Persist data between two pages with Next.js

I would like to refactor my Next.js webapp to have different pages handle different screens. Currently, I have this component holding several states to know in which screen I'm in. In the jsx section, I'm using {value && ... } to render the right…
Binajmen
  • 193
  • 2
  • 12
6
votes
4 answers

React Hooks: skip re-render on multiple consecutive setState calls

Suppose I have the following code: (which is too verbose) function usePolicyFormRequirements(policy) { const [addresses, setAddresses] = React.useState([]); const [pools, setPools] = React.useState([]); const [schedules, setSchedules] =…
5
votes
2 answers

Update state from deeply nested component without re-rendering parents

I have a form page structured more or less as follows:
5
votes
2 answers

Passing setState to child component using React hooks

I'm curious if passing setState as a prop to a child (dumb component) is violating any "best practices" or will affect optimization. Here is an example where I have the parent container passing state and setState to two child components, where the…
5
votes
2 answers

how to hide and show loading spinner - Activity Indicator react native, managing props and state

I have created a custom Activity Indicator class and I want to control the hide/show of it from where I use it. Here is what I have done. CustomActivityIndicator.js import React, { Component } from 'react'; import { ActivityIndicator, View,…
5
votes
1 answer

React ChartJS prevent new data from being added into state after it's redrawn?

I'm trying to update my chart using react-chartjs-2. I'm using date picker to filter different data and re-render the chart accordingly such as display data today, yesterday, last 7 days etc.. The data is being fetched from my database However, when…
Curious13
  • 291
  • 2
  • 17
4
votes
1 answer

Fast changing states without Redux

I'm working a website with fast changing states and many broadcasts, and I'm trying to create my own global state management with hooks and Context. The only solution I've found to avoid useless rendering is to create two context per state, one for…
4
votes
2 answers

React Native setState not working (functional component) at all, not even just out of sync

I appreciate anyone taking the time to go through my code and helping me with what's going wrong (printLang() is always printing 'en' or 'es' depending on which value it took on when I refreshed the app)! I'm using Material Dropdown for the first…
4
votes
1 answer

how I test useEffect with isLoading state

I want to build test when the isLoading state change the component. I know in the class component there is the way by do setState with enzyme, but I would like to know how I can do it here. const Spacex = () => { const [open, setOpen] =…
4
votes
2 answers

React - Invariant Violation: Maximum update depth exceeded

I have function for set my state from another class, but i got this following error Maximum update depth exceeded. This can happen when a component repeatedly calls setState inside componentWillUpdate or componentDidUpdate. React limits the number…
Hanif Nr
  • 164
  • 1
  • 10
1
2 3
29 30