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
10
votes
3 answers

setState not updating font awesome icon

I'm trying to dynamically render font awesome icon in myself written checkbox component. When I'm trying to update state of a with font awesome icon after clicking on it it is not updating. I've tried to move render to separate function and tried…
200OK
  • 701
  • 5
  • 14
10
votes
5 answers

Why is react setState method immutable?

Following comes from React tutorial: const squares = this.state.squares.slice(); squares[i] = 'X'; this.setState({squares: squares}); This code changes copied state.squares and assign it to orginal state.squares. Finally this changes original…
Tetote
  • 111
  • 1
  • 1
  • 5
9
votes
3 answers

Flutter Cursor of TextField moves to Position 0 after setState

I want to display something in a Text whenever a TextFields text changes: class _MyPageState extends State { String name; @override Widget build(BuildContext context) { TextEditingController c = new TextEditingController(text:…
julienduchow
  • 1,026
  • 1
  • 11
  • 29
9
votes
3 answers

This class is marked as '@immutable', but one or more of its instance fields are not final:

If I am declaring the variables as final then the values(variables) I want to change(on pressed) are in setState(){} so those variables can be changed What to do to prevent this? Also, why is it written widget.value? I have tried using static…
chaitanya Harde
  • 336
  • 1
  • 2
  • 8
9
votes
1 answer

React Native TextInput flickering on setState

I am building a Currency Input component using React Native TextInput. While the user is typing, the requirement is that the text should always be format in this way: $ + [integer-part] . [2 digits decimals] So for example if the user enters 2, it…
TheSoul
  • 4,906
  • 13
  • 44
  • 74
9
votes
1 answer

state is immediately available when setState is called after await

When calling setState after awaiting for another function and logging the state to the console - the value is immediately available. I know that setState is asynchronous and in all other cases, it wouldn't be available immediately after calling it…
9
votes
2 answers

React - Warning: An update was scheduled from inside an update function

I am dealing with a lot of problems about updating states in React for validation purposes, and always my state update after the render or something like that, anyway, I saw that many people solve this using a callback function in the setState, but…
9
votes
3 answers

How do I create a dynamic variable name in React?

In React, I am trying to dynamically create my state variable name using a variable and static text. 'level2' will be created by 'level' text plus a variable indicating what level (selectedItem.Level+1). this.state={ level1:[""], // city …
Bethany
  • 1,003
  • 5
  • 12
  • 18
8
votes
1 answer

How to correctly fetch APIs using Provider in Flutter

I'm currently dealing with a problem where I need some data from an API to show it into my widgets. I've following some Provider architecture pattern, where you setState two times: 1- When data is being fetched 2- When data is already fetched So the…
Nikssj_
  • 187
  • 2
  • 3
  • 11
8
votes
2 answers

React updating progress from a compute intensive function using setState

I have a simple React class showing this.state.progress (a number) and this state can be updated via updateProgress(progress) function. class App extends React.Component { constructor(props) { super(props); this.state = { progress:…
Saravanabalagi Ramachandran
  • 8,551
  • 11
  • 53
  • 102
8
votes
1 answer

Flutter: Calling SetState() from another class

I am trying to make a simple image that appears or disappears when a button is pushed. This button resides in a separate class to the image, so in Flutter this creates a massive headache of an issue. I have read many forums on this and I have…
Bisclavret
  • 1,327
  • 9
  • 37
  • 65
8
votes
3 answers

Empty set state what is the point?

I want to know the point behind calling setState without setting a new value to the variables. readLocal() async { prefs = await SharedPreferences.getInstance(); id = prefs.getString('id') ?? ''; if (id.hashCode <= peerId.hashCode) { …
Aya Elsisy
  • 2,029
  • 4
  • 13
  • 23
8
votes
4 answers

How to hide drawer in flutter after changing Scaffold.body value

I am using the method in this question to change the body of a Scaffold in flutter: Flutter Drawer Widget - change Scaffold.body content The method described works perfectly. Now I would like just the drawer to automatically close after the users…
juanarzac
  • 353
  • 1
  • 3
  • 11
8
votes
2 answers

React redux dispatch action before render container

I am very new to React-redux applications development and I am trying to understand how to dispatch another action as soon as the page loads. Following is my container code. I am using this (https://github.com/jpsierens/webpack-react-redux)…
Saad Anjum
  • 103
  • 1
  • 1
  • 8
8
votes
2 answers

setState in React based on current state

When updating a stateful component in React is it considered a bad practice when a component uses the current state to update the new state. For example if I have a class that stores whether a filter is open or not in it's state, is one of these…
Onaracs
  • 935
  • 3
  • 14
  • 22