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
2 answers

How to add JSON objects to array state in functional component in react.js

I need to keep all of the information that came from axios in the form of JSON in the state while using the map method. The problem is when I use the map method after the axios request, it just adds the last JSON to the state, but I have 9 objects…
0
votes
1 answer

Cannot update a single widget after all widgets are built

I’ve developed an application to organize quick menu for dinner. There are 6 recipes as list tiles. I have a scoreboard also. Scoreboard shows the total value of randomly generated menu. Score is calculated according to some numeric properties of…
Gökhan E.
  • 75
  • 8
0
votes
2 answers

How to setState in React when async mapping through array and API call

I'm trying to map() through my state, favorites, in React to fetch data from each entry in the state. The data should be stored in another state, stocks, and be displayed in a table. Map() through the state and fetching the data works, and I can see…
Binne
  • 19
  • 1
  • 9
0
votes
1 answer

Data fetched and set with setState inside useeffect doesnt appear in console log unless i set a timeout

function Groups() { const [gamesD, setGames] = useState([]); const notInitialRender = useRef(false); useEffect(() => { const gamesArray = []; const groups = [ 'EURO Grp. A', 'EURO Grp. B', 'EURO Grp. C', 'EURO…
David2203
  • 3
  • 1
0
votes
1 answer

Making button disabled if some date is fetched in flutter

I want to disabled the submit button of my form when data is fetched in a TextFormField. Above the TextFormField I have a datePicker, and if there is data in DB for the particular date selected in the datePicker, the TextFormFilled is filled with…
JS1
  • 631
  • 2
  • 7
  • 23
0
votes
2 answers

Different behaviour of setInterval in react vs vanilla javascript

I have been experimenting with setInterval. Both the codes were executed in Chrome. Below is my react component function App() { let [value, setValue] = useState(0); useEffect(() => { const id = setInterval(() => console.log(value),…
Rishabh Singh
  • 353
  • 2
  • 8
0
votes
1 answer

calling setState from onClick JavaScript function not working

I am trying to create a button that will make visible a form to edit any contact on my list. However, when I press the button, nothing happens. I have the initial state set to this.state = { contacts: [], showEditWindow: false, …
AZB
  • 7
  • 4
0
votes
0 answers

React: setState not updating?

I'm trying to update the state after a successful login attempt and the state is not being updated and the rest of the code after the setstate isn't being called either? console.log(`test`) // THIS GETS CALLED this.setState({ userinfo: { …
bee
  • 66
  • 7
0
votes
2 answers

Flutter : I want to change an image when you tap the image, and others are not affected by the tap

I am creating a simple app in Flutter. There are 7 images on 1 screen. I need a function that you can change an image when you tap one of the images. However, now when I tap an image, the other 6 images are also changed. I made a variable "isReal"…
S C
  • 29
  • 1
  • 5
0
votes
1 answer

I want a solution to change my state just after I get a future data without any tap action in Flutter

I get the error but still I want a solution to change my state just after I get a future data without any tap action. FutureBuilder( future: blogServices.articleComment(token, widget.article.id), builder:…
Shariar Saimon
  • 913
  • 6
  • 13
0
votes
2 answers

Getting TypeError: Object(...) is not a function error when trying to change a state property

I am very new to React and trying to implement the Rating feature in the code. Can anyone tell, why I am Getting TypeError: Object(...) is not a function error when trying to change a state property when the Rating component onChange property is…
abhishek narayan
  • 109
  • 1
  • 1
  • 10
0
votes
2 answers

React hooks: How do I update state on a nested object with array with useState()?

I have this form with questions and answers i get from the backend like this: { "id": 0, "seq": 0, "ccid": "string", "topic": "string", "riskOutcome": "string", "condition": "string", "comment": "string", "visible": true, …
0
votes
1 answer

Is there a difference between how we set the state in React?

first, sorry if already exists this kind on question. In order to set a state in a React class, we call setState(). My question is, is there a difference between v1: setState({firstState: value1, secondState: value2}) and v2: setState({firstState:…
Cinc
  • 67
  • 6
0
votes
1 answer

Flutter timer resets when switching page

In my flutter app there is a timer and a settings page. When the timer is running and I switch to the setting page (by using PageView), the timer gets reset or there is an error (Unhandled Exception: setState() called after dispose()) This happens…
0
votes
1 answer

Inserting function into file that extends component in React

I'm trying to create a useState to handle clicks for a dropdown button in React; but I can't use a function under a class that extends component, so I've been working on changing it as a constructor. I've tried multiple different ways but this was…