Questions tagged [state]

The contents of memory locations, at any given point in the program's execution, is called the program's state.

The contents of memory locations, at any given point in the program's execution, is called the program's state.

More information is available on Wikipedia.

9107 questions
141
votes
10 answers

How to Set/Update State of StatefulWidget from other StatefulWidget in Flutter?

For Example in the below code plus button works and able to update the text but the minus button does not. But if we press FloatingActionButton then the State is refreshed . The minus button is changing the value of the variable but not updating…
Ajay Kumar
  • 15,250
  • 14
  • 54
  • 53
136
votes
11 answers

setInterval in a React app

I'm still fairly new at React, but I've been grinding along slowly and I've encountered something I'm stuck on. I am trying to build a "timer" component in React, and to be honest I don't know if I'm doing this right (or efficiently). In my code…
Jose
  • 4,880
  • 8
  • 27
  • 49
134
votes
20 answers

How to save RecyclerView's scroll position using RecyclerView.State?

I have a question about Android's RecyclerView.State. I am using a RecyclerView, how could I use and bind it with RecyclerView.State? My purpose is to save the RecyclerView's scroll position.
陈文涛
  • 1,343
  • 2
  • 9
  • 5
132
votes
5 answers

android fragment onRestoreInstanceState

Am I missing something or do Fragments not have a onRestoreInstanceState() method? If not, how do I go about attaining something similar?
Shaun
  • 5,483
  • 10
  • 40
  • 49
128
votes
13 answers

React setState not Updating Immediately

I'm working on a todo application. This is a very simplified version of the offending code. I have a checkbox:

Writing Item

Here's the function…
lost9123193
  • 10,460
  • 26
  • 73
  • 113
122
votes
26 answers

Algorithm for Determining Tic Tac Toe Game Over

I've written a game of tic-tac-toe in Java, and my current method of determining the end of the game accounts for the following possible scenarios for the game being over: The board is full, and no winner has yet been declared: Game is a…
dreadwail
  • 15,098
  • 21
  • 65
  • 96
99
votes
7 answers

React - setState() on unmounted component

In my react component im trying to implement a simple spinner while an ajax request is in progress - im using state to store the loading status. For some reason this piece of code below in my React component throws this error Can only update a…
Marty
  • 2,965
  • 4
  • 30
  • 45
98
votes
13 answers

What is the best way to add a value to an array in state

I have an array in state, let's say this.state.arr. I want to add something to this state property, and then change some more properties. Option 1 onChange(event){ this.state.arr.push('newvalue'); ... …
Flion
  • 10,468
  • 13
  • 48
  • 68
96
votes
2 answers

Isn't Redux just glorified global state?

So I started learning React a week ago and I inevitably got to the problem of state and how components are supposed to communicate with the rest of the app. I searched around and Redux seems to be the flavor of the month. I read through all the…
Ryan Peschel
  • 11,087
  • 19
  • 74
  • 136
91
votes
3 answers

Preserving global state in a flask application

I am trying to save a cache dictionary in my flask application. As far as I understand it, the Application Context, in particular the flask.g object should be used for this. Setup: import flask as f app = f.Flask(__name__) Now if I do: with…
Profpatsch
  • 4,918
  • 5
  • 27
  • 32
83
votes
8 answers

How can I run an action when a state changes?

enum SectionType: String, CaseIterable { case top = "Top" case best = "Best" } struct ContentView : View { @State private var selection: Int = 0 var body: some View { SegmentedControl(selection: $selection) { …
user7885981
82
votes
7 answers

Why can't I change my input value in React even with the onChange listener

I am quite new to React and after going through some tutorials, I was trying the below code of mine. I made one component, passed props to it from a store, on componentWillMount I make a new state for component. Rendering is fine till now. Next I…
Saurabh Tiwari
  • 4,632
  • 9
  • 42
  • 82
78
votes
10 answers

How to detect when a image is loaded, that is provided via props, and change state in React?

I want to load a different image(fake avatar) while the final avatar image is loading. The idea is to detect when the prop image is loaded and change a state. Is it possible? Some ideas? Thank you! class ImageUser extends React.Component…
76
votes
11 answers

Does C++ support compile-time counters?

For the purpose of introspection, sometimes I've wanted to automatically assign serial numbers to types, or something similar. Unfortunately, template metaprogramming is essentially a functional language, and as such lacks global variables or…
Potatoswatter
  • 134,909
  • 25
  • 265
  • 421
75
votes
3 answers

Why give an "abstract: true" state a url?

I've be fiddling around with ui-router today in trying to better understand the scaffolding in Ionic and one thing that I noticed was that they give the abstracted state of "tabs" a url. The only times I've ever used abstract states, I used an…
spb
  • 4,049
  • 6
  • 22
  • 30