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

Setting state in render by using this.state

I've recently seen this type of react pattern where the state is being set in a render by using this.state: class ShowMe extends React.Component { constructor(props) { super(props); this.state = { showButton:…
user2456977
  • 3,830
  • 14
  • 48
  • 87
6
votes
4 answers

Push checkbox value to array on state onChange

I want to allow users to select days of the week from checkboxes. When a checkbox is checked, the value of that checkbox should update this.state.days. Instead of adding to the array, it's simply overwriting this.state.days. Tried using simple…
Connor G Roane
  • 153
  • 2
  • 2
  • 10
6
votes
2 answers

Accessing this.state in React-Native

Hi I'm new to React so bear with me. I'm want to store geoposition as a state. Seems nifty since any change in position will trigger a render, which is exactly what I want. During development I have a button that manual triggers the event by…
TOMvonMOM
  • 109
  • 1
  • 2
  • 9
6
votes
1 answer

Set state in child after it will receive props?

I have two components. One is UserBase on which ajax request is called to get values. When get those values and updated in state of header. Another component is Header. Its a child component of UserBase. So when the state updated then it pass it to…
Kushal Jain
  • 3,029
  • 5
  • 31
  • 48
6
votes
2 answers

React-Native this.setState() is not working

I am unable to get react-native's this.setState(); to work. When I run the onUpdate method, I can see the correct JSON object being returned. The issue is when the setState function is called nothing happens and the method fails. No more code is…
TimDOES
  • 91
  • 1
  • 2
  • 7
5
votes
1 answer

.map is not getting re-rendered after updating the state

I have fetched data using useEffect, and also getting the data on console. I've called the setState method to update the state, but the .map function is not working. Even on the console nothing is happening. import React, { useState, useEffect }…
Aman
  • 167
  • 2
  • 9
5
votes
1 answer

What's the best way to batch state updates from async calls in React?

I understand from this post that React doesn't automatically batch state updates, in the case that an event is non-react based i.e. setTimeout, Promise calls. (In short any event from Web APIs.) This differs from react-based events, such as those…
JimmyTheCode
  • 3,783
  • 7
  • 29
  • 71
5
votes
3 answers

Antd Notification appearing twice?

I am using antd notification component as follows import { notification } from "antd"; const Notification = ({ msg, type, clearMsg }) => { return (
{notification[type]({ …
Emma
  • 257
  • 6
  • 14
5
votes
0 answers

react-sortablejs - list won't update and component won't re-render

I'm trying to build a 'put the words in order' typical language learning activity. The user is supposed to start by dragging the first word of a sentence to its right place and move on from there. Meanwhile, I'm checking whether the next word is in…
Padeti
  • 71
  • 4
5
votes
3 answers

Filter The List Using Multiple CheckBoxes in React Js

Hello guys i am trying to filter the list of array of objects onClick of the checkbox based on a condition, but my else condition in handle method's is returning me a same array the state doesn't change,so i want default list that is remove…
ali
  • 492
  • 2
  • 7
  • 18
5
votes
5 answers

reactjs: setState being called twice in a function called once? why?

EDIT: since the code snip does not reproduce the bug - here is a link to the github repo: (code is far FAR from complete) https://github.com/altruios/clicker-game I have run it on two computers now - both with the same behavior the code snip doesn't…
altruios
  • 986
  • 1
  • 10
  • 29
5
votes
4 answers

Flutter - Provider - setstate or markneedsbuild() called during build

I have a project with Flutter. I am using Provider (4.0.5) for state management. I am getting this warning, "setstate or markneedsbuild() called during build" This is big problem for me. I think this problem will be grow in release mode. How can I…
Faruk AYDIN
  • 205
  • 1
  • 4
  • 14
5
votes
3 answers

Stateful Widget updation on calling it with different parameters, not updating?

i just started learning flutter, im using Stateful widget the following code below is the main.dart file void main() { runApp(App()); } class App extends StatefulWidget { @override _AppState createState() => _AppState(); } class _AppState…
5
votes
2 answers

react-draft-wysiwyg - Warning: Can't call setState

I did make a simple react app with react-draft-wysiwyg, but I get a warning. import React from "react"; import ReactDOM from "react-dom"; import { Editor } from "react-draft-wysiwyg"; import…
5
votes
2 answers

Set state based on previous one in render function

I recently read the react.js documentation and found inconsistencies in setting the state based on previous state value. Here is that chunk of code: class Example extends React.Component { constructor(props) { super(props); this.state = { …