score:0
setstate(updater[, callback])
use callback in setstate to read new value. setstate
is async and you are expecting your state to be updated instantly. to make sure your state got updated, you would have to leverage on call back function passed in as second argument.
this.setstate((state, props) => {
return { notsaved: size }
}, () => console.log(this.state.notsaved, 'updated notsaved'));
detailed explanation by dan on why is setstate asynchronous?
: https://github.com/facebook/react/issues/11527#issuecomment-360199710
Source: stackoverflow.com
Related Query
- React setState hook not updating dependent element if passed a variable as opposed to explicit text
- React setState not updating state
- React setState not Updating Immediately
- React Native: setState not updating immediately when logging in console
- setState not working for updating an array in React
- React hooks state variable not updating after rerender
- React hooks setState not updating immediately
- React not updating state with setState with Array of object
- Why is this variable from the Redux store not in the `this.props` on React page?
- React useState, setState in useEffect not updating array
- Why is the state not updating inside this react Hooks component?
- How can I solve this problem. React Router not updating routing on hosting
- Why is React setState hook not updating immediately?
- React setState not updating checkbox checked state
- React setState not updating reduced array
- React Not Updating Render After SetState
- setState in react function not updating in promise method
- setState in React not updating my rendered catalog
- setState not setting state variable React
- React setState not updating state in AG Grid onCellValueChanged callback
- React component not updating after prop is updated using setState
- React - changing state not updating elements rendered from variable
- React Hooks state not updating variable in view
- React hooks - setState is not updating the state properties to show sidebar
- React not updating state with setState correctly inside promises
- Completely stumped at this reactjs logic, of a variable not updating the state of a component
- React Component not updating after calling setState in SocketIO event listener
- React - setState not updating array
- why my React setstate is not updating immediately?
- React setState {} not setting variable
More Query from same tag
- Cannot access key values in an object with React
- Radio Button background and checked
- Why is the value of a React controlled input element not being updated properly from a Chrome extension?
- Showing number of entries needed in antd table in react JS
- Can print out value, but in setState its "undefined"
- Target native dom element <input>...</input> with styled-components
- Why isn't the link color changing back to its previous color on mouse out in react?
- useContext with React Hooks
- Fetching data and conditional rendering with React useEffect
- React: close other SubMenus when another SubMenu open
- How to use context in different component
- Unhandled Rejection (TypeError) on callback passed to react component
- How to pass an Event Object into a nested function?
- add/remove text multiple line for javascript
- Server rendering React js on a static website
- Property not found in props of React element `form`
- React not rendering data coming from reflux store
- Send dispatch and redirect after state is updated in redux ?
- Search in the multiply tree view doesn't work properly
- Why won't Axios give me a response with Redux actions?
- How can I update an object inside array of state?
- When using antd table, with checkbox selection, the checkbox is cleared
- How to show placeholder instead of the state's value at pageload?
- Cannot read property 'scrollIntoView' of undefined in Reactjs
- How to update a model's "meta" state with latest redux-orm version (0.9.x)?
- SVG in React Component
- Render special characters in placeholder JSX
- React get value of object from localstorge
- React Native - How to perform a really soft vibration?
- Nested Row with Table Row with Bootstrap 4 / ReactJS