Questions tagged [setstate]

Use for questions relating to the [setstate] method and component/widget state management in [reactjs] and [flutter].

setState is a component method in and which updates the local component/"widget" state and triggers a re-render of the component based on the new state.

Resources

2626 questions
0
votes
1 answer

Correct way to manage state on dynamic widgets in Flutter

I have a list of categories in sqlite, I got those rows across streambuilder, then, I create a list of switch widgets. In each switch widget ontoggle event I change the source value and I call setState method, but, this causes the execution of the…
elchente23
  • 163
  • 5
  • 13
0
votes
0 answers

Store response data from multiple axios get requests inside componentDidMount()

I am using promise.all inside componentdidmount to get response.data from two apis. constructor(){ super(); this.state = { data: [], p1: [], p2: [] }; } async componentDidMount() { const [res1,…
0
votes
0 answers

Why setState in setTimeount not cause Maximum update depth exceeded error

Currently, I want to forceUpdate function component, I work around and find one way function useForceUpdate() { const [, setValue] = useState(0); // integer state return () => setValue(value => value + 1); // update the state to force…
0
votes
2 answers

How do I change a state after getting data from API?

constructor(props) { super(props); this.state = { message: "" }; } async getData() { this.setState({...this.state}) await axios.get("https://g...") .then(function(response) { …
Audrey Wong
  • 71
  • 1
  • 1
  • 8
0
votes
3 answers

Cannot call setState() when attempting to update list in todo app

This seems to be a common issue, but I've tried several configurations and am consistently getting the error message Warning: Can't call setState on a component that is not yet mounted. I have used setState() in similar ways in other components of…
hbarnett91
  • 43
  • 5
0
votes
1 answer

How to set value on selected items with checkboxListTile

What is the correct way to Setstate of checkboxListTile to get both toggle button and added value to it? What I want is when you check the box, You see the check button. then the value added into the base price. Please kindly…
0
votes
1 answer

How to use setState to update Likes in nested object array

I need to know how to write an updateState method to update the likes in this nested object array. My state: const [comments, setComments] = useState([ { name: 'Chelsea Hagon', likes: 12, replyVisible: false, message: 'You…
0
votes
0 answers

How can I update an obect to the value of another object with the same structure?

I have two objects: filter: { brand: [], size: [], orderBy: 1, page: 1, pageSize: 15, search: search, condition: [], gender: [], offeredBy: [], color: [] }; tmpFilters: { brand: [], size: [], orderBy: 1, …
Arinton Akos
  • 145
  • 2
  • 10
0
votes
1 answer

Which one is executed first Fetch or setState?

I was trying to send data from frontend(React) to backend(express) from a HTML form, and clear the fields after submit. This is what it looks like. Here item and amount are state of controlled components. So my question is as I'm updating state…
Nakul Gopal
  • 60
  • 1
  • 4
0
votes
1 answer

Why is this setState function working abnormally

I added a timer variable in state to change every second by 1 Why is it is rendering with 2,4,6,.. every second rather than 1,2,3,.. and how to imporove it ? import React, { Component } from 'react' export class UseRefTimer extends Component…
0
votes
1 answer

React Native - LongPress and display extra information

In React Native, I would like to achieve the following outcome (example): example1 example2 On Long Press of the image (or touchableOpacity), I hope to display an overlay view of some extra information (could be images or text). The information…
cel-0207
  • 31
  • 7
0
votes
1 answer

setState not running in nested function

this.setState at the end of constructBoard doesn't appear to run when contructBoard is called. The function runs and works as intended other that setState not appearing to run. The callback function doesn't run either. class Board extends Component…
Valisea
  • 11
  • 1
0
votes
1 answer

setState() is not working inside my widget, since my that widget is built on the bottom of the widget tree, then how can I rebuild that widget?

I used Navigator.push to navigator to next screen and after I pop that screen I could not able to rebuild the old screen. And also I want my code to rebuild if user on pressed the login button //This is my stateful Widget class LoginpageClass…
0
votes
1 answer

React - State set inside useEffect axios request is empty

Hey, I've got a PortfolioPage component (code below) calling a GET request to my api through the axios library inside the component useEffect. After the request it sets the portfolio property using the setPortfolio hook. Then, I pass the portfolio…
david plotkin
  • 33
  • 1
  • 8
0
votes
1 answer

React state = understanding how to read state after updating

I'm pretty proficient in JavaScript but learning React. I'm trying to make tic-tac-toe. When I get a winner, I want the this.state.message to update immediately, the this.state.done to change to true immediately, and the this.state.turn to not…
phershbe
  • 169
  • 4
  • 12
1 2 3
99
100