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
608
votes
17 answers

How to declare global variables in Android?

I am creating an application which requires login. I created the main and the login activity. In the main activity onCreate method I added the following condition: public void onCreate(Bundle savedInstanceState) { …
Niko Gamulin
  • 66,025
  • 95
  • 221
  • 286
479
votes
23 answers

Updating an object with setState in React

Is it at all possible to update object's properties with setState? Something like: this.state = { jasper: { name: 'jasper', age: 28 }, } I have tried: this.setState({jasper.name: 'someOtherName'}); and this: this.setState({jasper: {name:…
JohnSnow
  • 6,911
  • 8
  • 23
  • 44
448
votes
26 answers

How can I update state.item[1] in state using setState?

I'm creating an app where the user can design his own form. E.g. specify name of the field and details of which other columns that should be included. The component is available as a JSFiddle. My initial state looks like this: var DynamicForm =…
martins
  • 9,669
  • 11
  • 57
  • 85
318
votes
21 answers

How can you do anything useful without mutable state?

I've been reading a lot of stuff about functional programming lately, and I can understand most of it, but the one thing I just can't wrap my head around is stateless coding. It seems to me that simplifying programming by removing mutable state is…
Mason Wheeler
  • 82,511
  • 50
  • 270
  • 477
272
votes
4 answers

React.Component vs React.PureComponent

The official React docs state that "React.PureComponent's shouldComponentUpdate() only shallowly compares the objects", and advises against this if state is "deep". Given this, is there any reason why one should prefer React.PureComponent when…
semuzaboi
  • 4,972
  • 5
  • 20
  • 35
269
votes
10 answers

How to prevent custom views from losing state across screen orientation changes

I've successfully implemented onRetainNonConfigurationInstance() for my main Activity to save and restore certain critical components across screen orientation changes. But it seems, my custom views are being re-created from scratch when the…
Brad Hein
  • 10,997
  • 12
  • 51
  • 74
215
votes
9 answers

Where to write to localStorage in a Redux app?

I want to persist some parts of my state tree to the localStorage. What is the appropriate place to do so? Reducer or action?
Marco de Jongh
  • 5,270
  • 3
  • 17
  • 29
210
votes
7 answers

Remove the complete styling of an HTML button/submit

Is there a way of completely removing the styling of a button in Internet Explorer? I use a css sprite for my button, and everything looks ok. But when I click the button, it moves to the top a little, it makes it look out of shape. Is there a css…
Saif Bechan
  • 16,551
  • 23
  • 83
  • 125
199
votes
12 answers

React setState not updating state

So I have this: let total = newDealersDeckTotal.reduce(function(a, b) { return a + b; }, 0); console.log(total, 'tittal'); //outputs correct total setTimeout(() => { this.setState({ dealersOverallTotal: total }); },…
The worm
  • 5,580
  • 14
  • 36
  • 49
188
votes
5 answers

Does React keep the order for state updates?

I know that React may perform state updates asynchronously and in batch for performance optimization. Therefore you can never trust the state to be updated after having called setState. But can you trust React to update the state in the same order…
darksmurf
  • 3,747
  • 6
  • 22
  • 38
184
votes
6 answers

How can I wait for setState to finish before triggering a function in React?

Here's my situation: on this.handleFormSubmit() I am executing this.setState() inside this.handleFormSubmit(), I am calling this.findRoutes(); - which depends on the successful completion of this.setState() this.setState(); does not complete before…
malexanders
  • 3,203
  • 5
  • 26
  • 46
177
votes
8 answers

Vuex state on page refresh

My app uses the Firebase API for User Authentication, saving the Login status as a boolean value in a Vuex State. When the user logs in I set the login status and conditionally display the Login/Logout button accordingly. But when the​ page is…
boomboxboy
  • 2,384
  • 5
  • 21
  • 33
153
votes
10 answers

Advantages of stateless programming?

I've recently been learning about functional programming (specifically Haskell, but I've gone through tutorials on Lisp and Erlang as well). While I found the concepts very enlightening, I still don't see the practical side of the "no side effects"…
Sasha Chedygov
  • 127,549
  • 26
  • 102
  • 115
150
votes
3 answers

How to add a custom button state

For instance, the default button has the following dependencies between its states and background images:
Vit Khudenko
  • 28,288
  • 10
  • 63
  • 91
148
votes
2 answers

AngularJS ui router passing data between states without URL

I am facing this problem of passing data between two states without exposing the data in the url, it's like user cannot really directly land on this state. For example. I have two states "A" and "B". I am doing some server call in state "A" and…
vijay tyagi
  • 2,226
  • 3
  • 20
  • 31
1
2 3
99 100