score:4
Accepted answer
first, welcome! you should have probably made it more clear that this question is about react.
now to the answer, every state modification would be made using setstate
, so your addfavourites
function should be like this:
addfavourites() {
let data = this.state.data.map((e) => {
e.favourite = false;
return e;
});
this.setstate({ data: data });
}
Source: stackoverflow.com
Related Query
- React - Adding a property to an object inside of array in component's state
- react js adding object to state array
- React redux - issues adding multiple items to an array in state tree object
- how do i update state in react for updating the value of an object inside an array using array.map function
- How to set a state of an array of object inside an array of objects in react
- Update property of certain object inside array in state
- How to change an object property in an array state container?? React Hooks useState
- updating a single object key value inside array of objects react redux state
- React state - updating property on object in nested array
- React - how set state in object of array , property text in function onChange here?
- Correct way of adding object inside an Array in React
- React not updating property from an object inside an array
- Change the state value of the property of a particular object that is inside an array
- Setting state of an object property inside array of objects based on a computation after match : reactjs
- Rendering React app does not apply when adding items to an array inside a state
- React update state array object single property
- Adding to object that contains an array an object in state in React
- Setting a property of an object inside array of objects based on a match: React JS
- adding new object inside of array of objects in react
- React js adding array in a useState object property
- Access Array of objects inside another object in React State
- react updating state in an array inside of an object which is inside of another array
- Toggle Boolean property inside Object in Array of Objects in state
- How to push Value in an array exist inside in an object of state in react
- How to change the property of an object inside an array propertly in react
- Adding data to Array inside an object using React Hook
- Updating the array object in React state using immutability helper
- Replace object in array on react state
- ReactJS updating a single object inside a state array
- React Js, adding new object to an array
More Query from same tag
- MUI how can I change the icon inside the TablePagination component?
- React SignalR - Do not send bearer token in URL
- How to replicate class based components async setState method with react-hook
- Redirect in React with Typescript
- I can't make text direction right to left?
- How to show value calculated from input form to the screen
- React navigation with router go back button change state
- go back button doesn't navigate back
- Cannot destructure property .... as undefined
- css modules & cssnext custom properties in react + webpack
- Need explanation on event change handler code
- React-testing-library wraps component with <div> which produces warning
- Async/Await in Redux
- struggling with REACT (setState())
- How to clean up a Redux "useDispatch" action inside useEffect?
- what is the point of having static propTypes in reactjs and does it solve any problem or is it just a pattern
- Returning an array to React component from fetch call in Redux
- Getting " Uncaught TypeError: Cannot read properties of undefined (reading 'Items')"
- How do you simulate an keyDown enter event (or others) in Enzyme?
- How can I fetch data with an array in react?
- Handing 2D-Array from Spring boot to React
- stop setInterval and if not work in react native function
- Chaining variable number of filter functions in Javascript
- Proxy request error when trying to send post request from React to Node, proxy is working fine on get requests
- Event Handler for onSelect in InfiniteCalendar
- Data from database displaying in the State but not on screen in React.js
- How to store values in react, that are not state changing?
- TypeError: Cannot read property 'current' of undefined focus
- Trigger function onclick when loading HTML from external source
- Changing CSS Attribute on click in React while using Styled Components