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

How to 'setState' only to the appBar icons instead of 'notifyListeners'

I have an appBar with one icon, this icon has a number which have to be updated after I change somethings in the app. I was using notifyListeners(), but this command is cleaning a list I need so I have to update that number in appbar without…
user14736790
0
votes
0 answers

setState not updating in another function

I am updating a variable in one function and using it in another const callNum = () => { let number = 5; number = number * number; setNum(number); }; const callFun = () => { console.log("hello"); callNum(); …
Simran Birla
  • 136
  • 6
0
votes
2 answers

react (class based) : How can I update JSON object in parent component using setState after the object being passed in function from child to parent?

I've JSON data at "Data.js" and in "App.js" it is initialized in state. In "updateList" method of "App.js" I am getting "dataa" - from "insertIt" of "Form.js" and I need to "setstate" too in "updateList" of "App.js". please help me correct my…
0
votes
1 answer

Flutter setState rebuilds but does not properly draw replaced widget

I am somewhat confused as to why a widget is not properly redrawn, even though the build method is invoked. Basically a card is drawn (SplashCard), filling most of the screen. This card is swipable (tinder style). When one slides it to the right, it…
Denis
  • 3
  • 2
0
votes
1 answer

useEffect tries to read property of object before the state was updated in React

I am cascading data to my components with createContext() in React. In this I have an API call, where I'm fetching two different arrays of objects, mapping over them, and creating a final set of data like: const [organizationData,…
labilouser
  • 177
  • 1
  • 2
  • 9
0
votes
2 answers

Flutter : correct way to call "nested future"

What is the best way to call nested future in Flutter ? Or flutter in general ? In my app, I have to get the current user (which have its data in final storage = new FlutterSecureStorage();. From this user, I call an API which is by the user id.…
morganXap
  • 35
  • 6
0
votes
2 answers

List's icon state reverts when I scroll

I'm rendering a list fetched from api on the screen. I have a save button for each Item in the list which changes on click. it works fine but when I scroll the list it reverts. I think its because the list builder is building the list again and…
Benyamin
  • 1,008
  • 11
  • 18
0
votes
1 answer

Why is my star system isnt work in flutter

This is my code for making the star turn yellow and grey consistently, but it didn't work. Why? Widget placeButton(BuildContext context, String name, String image, String id) { var color; var isClicked = true; return…
0
votes
0 answers

Nothing was returned from render when using setState in class component

I seem to be getting this error message when trying to update my state once an image has loaded using the onLoad event. I have a return statement in my class although it is complaining I don't. I receive this message upon runtime: 'Error:…
ashley g
  • 857
  • 3
  • 11
  • 21
0
votes
0 answers

React - render sequential state updates

I have a case where I need to update the parent before showing a modal in a child (portaled to the end anyways). I wish to have a sequence where: The parent updates a state The parent re-renders to update some DOM elements (with unchanged…
Samson Liu
  • 460
  • 4
  • 20
0
votes
0 answers

Tab barView doesn't automatically get updated by setstate until the tab bar is clicked on

I am using a Tabbar widget which controls a TabbarView. When I call on setstate after changing the value of a variable named "searchTerm", the anticipated change isn't updated in the tabbarView widgets until I click on any of the tabs.I need the…
0
votes
1 answer

Flutter random Image.asset changes on hovering Button?

I want to show a random picture everytime the user enters the page. I also have a Button (the red container with hovering) on this page, and when the user is hovering it, a new random picture shows, but it shouldn't change since the page was loaded.…
Cubii
  • 41
  • 5
0
votes
2 answers

React setState not updating

handleSkipThisQuestionClicked = () => { const { answersDict, currentIndex, currentQuestionGroupId } = this.state; if (currentIndex < answersDict[currentQuestionGroupId].length - 1) { …
Sanjay Kapilesh
  • 269
  • 1
  • 4
  • 16
0
votes
1 answer

Switch Statement Causing - React limits the number of renders to prevent an infinite loop

In my React code below, I'm getting an error: Error: Too many re-renders. React limits the number of renders to prevent an infinite loop. If I comment out the switch statement, the error goes away. So, what in this switch statement is causing…
Adam Norton
  • 512
  • 2
  • 5
  • 21
0
votes
1 answer

React conditional re-rendered not triggered

Edit The issue was a condition I have not noticed in the shouldComponentUpdate lifecycle method. So please check this if you encounter any issues such as mine. Edit I've pretty much reached an impasse, and I do not understand why a simple…