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

React hooks: Can't update state inside function component

I'm new to React and am trying to figure out how to make a phonebook. I've gotten quite far but I'm having an issue I can't solve. I'm using React Hooks. Everything works fine, except for when I call the setNewNumber('') and setNewName('') functions…
JumpyWizard
  • 25
  • 1
  • 6
2
votes
3 answers

React setState array not getting sorted

My code is this: handleFavourite = id => { const { restaurants } = this.state; let newRestaurants = [...restaurants]; newRestaurants = sort(newRestaurants, 'favourite'); console.log(newRestaurants); // ALL GOOD this.setState({…
Xeen
  • 6,955
  • 16
  • 60
  • 111
2
votes
2 answers

State with IO in Haskell for CLI application

I am trying to write a simple implementation of the game Hangman in Haskell and one problem I have is keeping the state of the game. A simplified / abstract version of my problem looks like this: advanceState :: Char -> [Char] -> [Char] advanceState…
Niklas Vest
  • 872
  • 6
  • 20
2
votes
2 answers

Can't access store from Vuex [Quasar]

I'm trying Quasar for the first time and trying to use the Vuex with modules but I can't access the $store property nor with ...mapState. I get the following error 'Cannot read property 'logbook' of undefined' even though I can see that the promise…
Braganca
  • 106
  • 1
  • 8
2
votes
2 answers

How can set array useState in loop for add more item in default array?

I had an array with 10 item First, I added 5 item in useState const [dataList, setDataList] = useState([]) useEffect(() => { const newArr = [] for (var i = 0; i < 5 && i < data.length; i++) { newArr.push(data[i]) } …
Buzz
  • 59
  • 3
  • 8
2
votes
1 answer

React Hooks useState Event Handler With Styled Components

I have a parent div ImgClust1 that onClick I want styled-components inside of it to change some styling based on state. Basically, as of current structure, on hover the TopLine, RightLine, LeftLine, and BotLine components transform and essentially…
yaboy618
  • 127
  • 10
2
votes
2 answers

How do i define a property on a Type in a function component? TS2339 ERROR

I have the following code; import React, { useContext, useReducer, useEffect, } from 'react'; const AppContext = React.createContext({}); const App = () => { let initialState = { lang: 'en', color: 'blue'}; let reducer = (state,…
2
votes
3 answers

How to update redux state using a react variable passed up to the component from a child

Im trying to update my Redux state in a component using a variable passed up to that component from a child, following a form submital callback. The form submits a users comment, which i want to store in my redux state. I'm unsure how to send this…
Sean
  • 587
  • 4
  • 20
2
votes
0 answers

I had multiple triggers A,B which caused transitions between two states S1 and S2, would that pose any problems?

I looked into some state diagrams online and don't see any with multiple events which lead to transitions between two states... For example I have two states A and B and a number of events that can occur X Y and Z that can make A --> B…
user716129
  • 143
  • 2
  • 7
2
votes
2 answers

Looping of constructor this.state

I would like to declare many variables into the state. How to use dynamic method to do that? For example: constructor(props) { super(props); this.state = { test1: this.props.navigation.state.params.rowData.test1, test2:…
Howard Lam
  • 41
  • 3
2
votes
1 answer

setState on dynamic/list/array variable flutter

i know it's a bit messy, and I'm pretty new with flutter, I'd quite understand how state behaves on react, but state management on flutter seems doesn't behave the same way on array variable. When I tried to setstate with a different approach, it…
Ariel Malada
  • 21
  • 1
  • 3
2
votes
2 answers

React Hooks setState function not setting state

I'm trying to build a chat application, and I have a function for selecting users you want to add to the chat. It is in the following component (I've left out the import statements and one of the functions for brevity): const AddUserBox = (props) =>…
Chris Capua
  • 37
  • 1
  • 4
2
votes
1 answer

Can I mock an interactive program using the state monad?

Based on an answer here I was inspired to try and make a program where the state monad could be swapped for the IO monad and it would still work. So far I came up with: {-# LANGUAGE FlexibleInstances #-} import Control.Monad.State class Monad m =>…
Cameron Ball
  • 4,048
  • 6
  • 25
  • 34
2
votes
1 answer

When removing items from futurebuilder it doesn't update

I have a futurebuilder that calls an API connected to DynamoDB. When I remove an item from dynamoDB however it doesn't update my list unless I navigate away from the screen and then come back, allowing the FutureBuilder itself to rebuild. I've…
Jet.B.Pope
  • 642
  • 1
  • 5
  • 25
2
votes
2 answers

How to Use State inside the function in React JS?

I got this error when I call this.state.testState inside a function. TypeError: Cannot read property 'state' of undefined class Home extends Component { constructor(props){ super(props); this.state = { testState:…
larp
  • 1,017
  • 1
  • 14
  • 23