score:0
if your comparison is between title.rendered
not this.state.title.rendered and this.state.data.title.rendered
then i think the reason is that the setstate is asynchronous and maybe before the value of data is put on the state you are calling it already in some point inside render hence it's not yet available but as for title.rendered it's just a constant that is sitting there and waiting to be used. you can how ever make sure this works by doing a check ie if you did not expect just an answer then you can do something like
this.state.data && this.state.data.title.rendered
score:2
each setstate
call results in a different state, you may want to use destructuring assignment on responsejson.data
like so: this.setstate({ ...responsejson.data });
// each value reprensets an entry
this.setstate({ title, fimg_url, content });
// state = { title: 'value', fimg_url: 'value', content: 'value' };
// responsejson is a value of `data` key
this.setstate({ data: responsejson });
// state = { data: { title: 'value', fimg_url: 'value', content: 'value' }
// you may want to use:
this.setstate({ ...responsejson.data });
Source: stackoverflow.com
Related Query
- can't perform a react state update on an unmounted component issue with useEffect
- React js state update issue
- react hooks update state issue
- How to update nested state properties in React
- Can't perform a React state update on an unmounted component
- React useEffect causing: Can't perform a React state update on an unmounted component
- React input defaultValue doesn't update with state
- Does React batch state update functions when using hooks?
- React-hooks. Can't perform a React state update on an unmounted component
- Update component state from outside React (on server response)
- onChange event for React child component to update state
- How to update array state in react native?
- How to update react state without re-rendering component?
- React hooks: How do I update state on a nested object with useState()?
- "Cannot update during an existing state transition" error in React
- How to update object in React state
- UI not re-rendering on state update using React Hooks and form submission
- how to update multiple state at once using react hook react.js
- Can not update state inside setInterval in react hook
- How to update the state of a sibling component from another sibling or imported component in REACT
- Warning: Can't perform a React state update on an unmounted component. In a functional component
- How to update the router state on history.replace in react router?
- What's the best alternative to update nested React state property with setState()?
- React - State Update value only of Particular key
- React Apollo: Dynamically update GraphQL query from Component state
- Update React Hooks State During Render Using useMemo
- React hooks function component prevent re-render on state update
- React does not refresh after an update on the state (an array of objects)
- React not re-rendering after array state update
- Form created with React doesn't update the backing state object
More Query from same tag
- React - getDerivedStateFromProps - field values will load the props but won't change
- When value is assigned to components state, why console.log prints the previous state?
- Getting API URL from the External File which is not a part of the React app
- ReactJS how to add momentJS to object attribute
- Difference between location.pathname and match.url in react-router-dom?
- How can I insert a line break into a String component in React JS?
- React app using API with another origin (CORS)
- if not on route('/') go to that route after submitting form, react
- Mern Stack Application Deployment on Heroku (remote: npm ERR! Failed at the server@1.0.0 heroku-postbuild script.)
- Warning : Failed child context type: Invalid child context 'virtualizedCell.cellKey' of type 'number' supplied to 'CellRenderer', expected 'string'
- passing content of card from one page to other in react
- How to access current state on Redux Toolkit on createAsyncThunk
- using React router with Next JS route
- Fetch POST Request doesn't return response sent using res.send('sampletext');
- How to change the ajax sort params in Tabulator?
- React-bootstrap - TABS component - render children components
- How can I use date component in a React form
- How can I delete a row using the reduce method from my redux store
- React Native: Using lodash debounce
- how can i use NavLink to redirect from component to another component
- Component output by pressing the ReactJS button using the props
- After the page is reloaded, the url created with useHistory push is deleted
- Using Immutable JS and Redux - action is undefined
- How can I upload image to database with react-image-upload dependency?
- How to preserve object keys in lodash filter
- fetch json file on react component render,using async await
- Accessing "this" from a different scope
- How to integrate react DnD with react fullcalendar?
- Argument of type 'unknown' is not assignable to parameter of type '{}'
- saving state into localstorage in react