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

pushState: what exactly is the state object for?

I've read a dozen of times now that the state object could exists of multiple key|value pairs and that it is associated with the new history entry. But could someone please give me an example of the benefits of the state object? Whats the practical…
campari
  • 985
  • 2
  • 8
  • 11
72
votes
3 answers

Where Should Model State Be Stored In Angular.js

I'm finding Angular's use of models confusing. Angular seems to take the approach that a model can be anything you like - I.E. Angular does not include an explicit model class and you can use vanilla JavaScript objects as models. In almost every…
Undistraction
  • 42,754
  • 56
  • 195
  • 331
70
votes
6 answers

Where can I get a list of Countries, States and Cities?

This probably seems like a duplicate, since there are identical questions out there. Unfortunately all of the answers to all of these questions are missing one detail: the states. Where can I get a list of countries, states and cities? For example,…
Jonathan
  • 32,202
  • 38
  • 137
  • 208
69
votes
7 answers

How to use onClick with divs in React.js

I'm making a very simple application where you can click on square divs to change their color from white to black. However, I'm having trouble. I'd like to use the onClick function to allow a user to click on a square to change its color, but it…
Leia_Organa
  • 1,894
  • 7
  • 28
  • 48
69
votes
5 answers

ReactJS this.state null

Let me preface this by saying I am a novice to ReactJS. I am trying to learn by making a simple site that populates data using React. I have a JSON file that contains link data that will be looped through with map. I have tried setting it as the…
Matthew Wisniewski
  • 691
  • 1
  • 5
  • 3
67
votes
2 answers

Maintaining complex state in Haskell

Suppose you're building a fairly large simulation in Haskell. There are many different types of entities whose attributes update as the simulation progresses. Let's say, for the sake of example, that your entities are called Monkeys, Elephants,…
rlkw1024
  • 6,455
  • 1
  • 36
  • 65
66
votes
5 answers

Android : How to update the selector(StateListDrawable) programmatically

I want to update the selector for a button programmatically. I can do this with the xml file which is given below
Mani
  • 2,599
  • 4
  • 30
  • 49
65
votes
4 answers

When is it OK to use an IORef?

One thing that has always confused me is whether or not it's an okay time to use an IORef. Are there any guidelines that should be followed when deciding whether or not to use an IORef for a task? When is a good time to use the State monad over an…
Rayne
  • 31,473
  • 17
  • 86
  • 101
61
votes
1 answer

React - how to pass state to another component

I'm trying to figure out how to notify another component about a state change. Let's say I have 3 components - App.jsx,Header.jsx,and SidebarPush.jsx and all I'm simply trying to do is toggle a class with an onClick. So the Header.jsx file will have…
agdev
  • 653
  • 1
  • 7
  • 5
57
votes
3 answers

How could I initialize the @State variable in the init function in SwiftUI?

Let's see the simple source code: import SwiftUI struct MyView: View { @State var mapState: Int init(inputMapState: Int) { mapState = inputMapState //Error: 'self' used before all stored properties are initialized }…
norains
  • 743
  • 1
  • 5
  • 12
56
votes
2 answers

Why does stringstream >> change value of target on failure?

From Stroustrup's TC++PL, 3rd Edition, Section 21.3.3: If we try to read into a variable v and the operation fails, the value of v should be unchanged (it is unchanged if v is one of the types handled by istream or ostream member functions). The…
user1823664
  • 1,071
  • 9
  • 16
55
votes
5 answers

When do I choose React state Vs Redux Store

I've been learning Redux and a part I'm unclear of is, how do I make a determination between using react state vs redux store and then dispatching actions. from my reading so far it looks like I could use React state in place of Redux store and…
JavaNovice
  • 1,083
  • 1
  • 12
  • 20
55
votes
3 answers

Angularjs ui-router. How to redirect to login page

I have 4 states: dashboard, dahboard.main, dashboard.minor, login. dashboard is abstract and it is a parent state for .minor and .main states. Below is my code: .state('dashboard', { url: "/dashboard", abstract: true, …
Yelnar
  • 674
  • 1
  • 7
  • 17
54
votes
7 answers

How to execute code before app exit flutter

I want to detect when a user quit my app and execute some code before but I don't know how to do this. I tried to use this package: https://pub.dev/packages/flutter_lifecycle_state but I have this error:…
luc
  • 1,301
  • 2
  • 14
  • 30
54
votes
2 answers

ASP.Net MVC and state - how to keep state between requests

As a fairly experienced ASP.Net developer just recently starting using MVC, I find myself struggling a bit to change my mindset from a traditional "server control and event handler" way of doing things, into the more dynamic MVC way of things. I…
TMan
  • 1,305
  • 1
  • 13
  • 17