score:4
Accepted answer
i believe you are confusing two related concepts: immutability - a technique which can be used in js vs immutable.js - a library to make the former easy.
here's an example of both (dataset is corrected a bit to valid js and to include a duplicate todo):
const data = {
item: {
name: 'somename',
todos: [
{ id: 1, name: 'todoname' },
{ id: 2, name: 'todoname2' },
{ id: 2, name: 'todoname2' },
],
},
}
console.info(
'immutable unique todos:',
data.item.todos.map((todo) => ({ ...todo, }))
)
console.info(
'immutable.js unique todos:',
immutable.fromjs(data).getin(['item', 'todos']).toset().tojs()
)
<script src="https://cdn.jsdelivr.net/immutable.js/3.8.1/immutable.min.js"></script>
immutable.js docs.
Source: stackoverflow.com
Related Query
- Working with complicated immutable objects
- Working with Audio objects in React/ Redux
- Replace of setState callback in react hook with useEffect hooks for complicated scenario not working
- Working with arrays of objects as props in React
- Typescript Declaration File working with generics and merged objects
- How to combine an array of JS objects with an existing immutable JS ordered map?
- Spread syntax not working as expected with array of objects
- useState not working with Array of Objects
- ShallowCompare not working with immutable js
- My ternary operarion with data from an arrray of objects in React is not working
- Working with a array of objects in React. Iterating error saying I cannot use object, use array instead
- Update one of the objects in array, in an immutable way with immer.js
- Update one of the objects in array, in an immutable way
- React native - objects are not valid as a React child (found: object with keys {$$typeof, type, key, ref, props, _owner, _store})
- React Router with custom history not working
- Extending styles with styled-components not working
- When working with lists and keys in React, can Keys contain whitespace/spaces?
- React router v4 not working with Redux
- onmouseover not working with React.js
- Formik & yup form validation not working as expected with VirtualizedSelect
- React Error Boundaries not working with React
- React JS not working with Internet Explorer 9
- React Native Image Not Working with specific URL
- React hook useRef not working with styled-components and typescript
- Some Tailwind styles not working in production with Next.js
- Webpack module federation is not working with eager shared libs
- React native mapping through array with object childs - working different as in react web?
- Tailwindcss not working with next.js; what is wrong with the configuration?
- Connect not working with StateLess component in Redux-react
- Fetch API not working with localhost/127.0.0.1
More Query from same tag
- Loop to dispatch a reducer in Redux
- How to avoid creating references of 'this' in ES6: const that = this when scope nested in React
- Setting showPrintMargin to false not working in React Ace Editor
- What is the meaning of & in css styling in react js
- Geolocation through React-Redux
- Can value of input box be set to to empty string on clicking submit button when the input is in a stateless functional component?
- How to pass props to styled component inside a loop
- How do you pass different props to different child components in a parent component?
- uri image is not rendering in React native Image view
- Meteor React Komposer: Execute Component Constructor AFTER ready subscription
- THREE.js Texture to Sphere with React
- Delete object from Firebase, React, ES6
- 404 page on Route not working as expected with children
- Handle Redux-form events
- react-select: pre-select a value in multi-select dropdown
- How to change value of Material-UI's Textfield on focus?
- Nextjs causing hard refresh when i click in the Link
- Is there a way to set an onClick to change background of a div element to a gradient using JavaScript/React?
- How to take post request by ReactJs in Ruby On Rails?
- Formik Storybook: Objects are not valid as a React child
- Change sticky navigation bar color scheme based on content below in React
- Material-UI withStyles not applying background color
- TypeScript: How to define the type when pass component in props in React?
- $(this) inside React Component
- Conditional Redirect on props status
- How to set state from props that is passed to the component in react?
- React material-ui (MUI) 5 conditional CSS classes
- Dropdown not picking items from the options list
- Separating logic and UI in my React component/API request
- React Hook useEffect Error missing dependency