score:0
Accepted answer
state update in react is asynchronous, so you should not expect updated values in the next statement itself. instead you can try something like(logging updated state in setstate callback):
this.setstate({
todoitems: {newtodoitems},// also i doubt this statement as well, shouldn't it be like: todoitems: newtodoitems ?
},()=>{
//callback from state update
console.log(this.state.todoitems);
})
Source: stackoverflow.com
Related Query
- I'm unable to change the array of an existing state
- useEffect Hook - how to detect the change of an object's property in a state array
- Unable change the state in componentDidMount properly
- Change state's array without changing the whole state (REACT / REDUX)
- Change the state of an element to show an array of Components after API call
- I cannot change the array in State
- Unable to save to array React state from the response from the server
- How to change the state of a specific value in an array with condition
- Button element in array with onClick property to change state the specific button that is clicked
- ReactJS: Change the index of an array in a state
- Access and change the state array element in main React App from grandchild
- How can I change the array key value before passing to the state in react?
- How do I change the state of an array of objects in React?
- I want to change the state of a single book in my react app but it changes state of the whole array
- How to change the state of an array of children components inside a parent using Hooks?
- Change the state input which is a JSON Object that is present inside an array of JSON
- Unable to push data to array and eventually update the state in react js
- Change the state value of the property of a particular object that is inside an array
- React, component not re-rendering after change in an array state (not the same as others)
- I want to change the state value of array while using Redux toolkit
- How to update a single object inside the array with useReduce on state change
- Editing array in state adds a new element instead of updating the existing (react JS)
- How to map an array , and change the state asynchrony using react-hooks
- How to identify a certain object id of an array to change the state of an element in the same object?
- How to change the value of array of items in a state in ReactJS?
- I am unable to mutate the array in the Redux state
- Rect - change the state of a property of an array mapper onclick (in functional no class)
- I want to change the value of the state with the next values from an array
- How do I change the state to a different object within an array of objects in a Redux Reducer
- how can I change the value of an object in an array being mapped from state react
More Query from same tag
- React: reading data passed as parameter in history.push
- How to override .MuiTypography-body1 class in Material UI
- resolving promises in a sequential order using javascript / react from contentful CMS
- net::ERR_SSL_PROTOCOL_ERROR on http POST to express server
- Input Field Onchange not allowing to type
- React: Enzyme's it local scope does not work
- React Router Navigation in multi step form
- How to update specific object in array NodeJS, MongoDB
- React hooks show more/less text like in youtube comments section
- React state cannot be changed
- React.Component vs React.PureComponent
- Sending API data using Link in Gatsby
- JSX props should not use .bind()
- How to create loading spinner with react js
- react-date-range create custom inputRanges
- Server side rendering + react router redirect
- A state is undefined object when using React and Redux , Router
- Why does chrome dev tools console show a link for Post 500 error in one website but not another?
- Using css module in react app. How can I get rid of styles keyword
- Not able to align menu items horizontally in navigation bar
- React - Can A Child Component Send Value Back To Parent Form
- passing id through Link to getServerSideProps :next js
- Webpack has been initialised using a configuration object that does not match the API schema. webpack install by "npm install webpack"
- Response Headers Empty
- Cannot connect apollo client to aws appsync
- Getting previous State of useState([{}]) (array of objects)
- Next.js pages using Link module not loading files with CSS import
- How to use object spread reduxjs/toolkit
- Arguments instead of Props in React Functional Component
- cannot read property '_id' of undefined when user signed out