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.

6971 questions
64
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
  • 28,305
  • 16
  • 83
  • 100
62
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,337
  • 4
  • 26
  • 46
62
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
  • 621
  • 1
  • 5
  • 3
62
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,225
  • 1
  • 34
  • 61
55
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
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
  • 15
54
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
  • 573
  • 1
  • 6
  • 5
54
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,021
  • 8
  • 15
53
votes
6 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
  • 3,364
  • 4
  • 31
  • 64
51
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,260
  • 1
  • 13
  • 17
49
votes
7 answers

How to restore a minimized Window in code-behind?

This is somewhat of a mundane question but it seems to me there is no in-built method for it in WPF. There only seems to be the WindowState property which being an enum does not help since i cannot tell whether the Window was in the Normal or…
H.B.
  • 136,471
  • 27
  • 285
  • 357
47
votes
5 answers

ST Monad == code smell?

I'm working on implementing the UCT algorithm in Haskell, which requires a fair amount of data juggling. Without getting into too much detail, it's a simulation algorithm where, at each "step," a leaf node in the search tree is selected based on…
mergeconflict
  • 7,861
  • 31
  • 63
47
votes
6 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,562
  • 6
  • 20
  • 39
43
votes
3 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
  • 915
  • 1
  • 8
  • 19
41
votes
1 answer

STArray documentation for newbies and State/ST related questions

I have a hard time to understand STArray from the documentation and other howtos/discussion I've found through Google. I've got some more related questions below. According to the documentation, STArrays are Mutable boxed and unboxed arrays in the…
bbtrb
  • 3,895
  • 2
  • 22
  • 30