score:3
Accepted answer
You can use the map
function to replace the item :
handleDuplicate = (id, nextId) => {
const currentItem = this.state.items[id];
const items = this.state.items.map(
item => item.id === nextId ? currentItem : item
);
this.setState(prevState => ({items});
}
Source: stackoverflow.com
Related Query
- ReactJS - replacing an object in an array with another
- Replacing object in array with another object, ReactJS
- ReactJS: replacing object from array with new value replaces whole array
- Create an Array of Object from another Array of Object with dummy object
- reactjs how to filter / check if a any object in an array is present in another array of objects?
- How to check if property of an objects of array matches with one of the values in another array of object
- ReactJS Hooks Update an Array with another Array
- How to replace array of one object key with another array of object key in react
- ReactJS - Swap out all the values in an array of objects in state with another array
- Images are not displaying with <li> tag in map function for array object in Reactjs
- Reactjs - Replacing array value from another
- ReactJS setState with object and array
- ReactJS - How can I push a "link" object to an array with unique values via a for loop?
- ReactJS How to loop through an array and fetch specific attribute of Object inside another array
- Instead of replacing the object it adds a new one in a nested array with React
- ReactJs : How to display a specific data of an object from an array of objects with a click
- How to transform an array with some deep nesting into another object in order to manipulate expanding initialState in React-table
- How to loop through an object with key and associated array and filter the array based on value presence in another array
- Filter an array of object with another array - returning two values
- How to avoid 'children with same key' when replacing state in ReactJs component
- React.js: loading JSON data with Fetch API and props from object array
- React efficiently update object in array with useState hook
- React native mapping through array with object childs - working different as in react web?
- Replace array item with another one without mutating state
- ReactJS - setState of Object key in Array
- ReactJS with Material-UI: How to sort an array of Material-UI's <TableRow> alphabetically?
- ReactJS updating a single object inside a state array
- ReactJS Array fill with key in JSX element
- Displaying multi dimensional array with ReactJS
- Finding the array index of an object with Javascript/React.js
More Query from same tag
- Sorting an array of objects based on the index after mapping through an array
- Building a Higher Order Component Error Boundary
- Add stop condition to map in React
- Object is possibly 'undefined' in typescript
- How to show components conditionally based on route
- How to model a HTML table with two cells per column in React?
- How might I uncheck all rows of MaterialTable(mbrn/material-table) with a button?
- setState inside a Promise function in a useEffect with hooks?
- How this.setState() (react.Component method) has access of his child's class state?
- Using Redux for dynamic wizard
- React - reusable Redux hook slice issue (Redux Toolkit, Typescript)
- mapDispatchToProps, dispatch and axios
- Redirect does not redirect to home page instead redirects to setup page with redux
- React does not compile my component in which I'm trying to use react-pdf
- How to make rounded slides in swiper.js
- use lodash for iterating the array and filter
- How do I access JSON file after filtering and pushing into array
- get rxjs subscription data once and reuse data later
- Iteration over a state object in React doesn't display anything
- Get position of 3 seperate divs in ReactJS
- Possible to hold multiple values within a single TextInput?
- ReactJS material makeStyles
- React Native Router Flux dynamic route
- How do I get my components to return a serialization of themselves?
- gatsby-plugin-preact is not working with react-bootstrap
- Handle Array of Object manipulation
- React: Text input keep loosing focus as I type
- How to replace the value of an array of objects in React
- How to remove duplicate values from dropdown in react
- Why am I getting generic "TypeError: Failed to fetch" errors?