score:5
Accepted answer
Array.prototype.filter
does not mutate the array, it creates a new one.
So this:
draftState.burgers.filter(el => el.id !== action.payload)
is not actually changing draftState.burgers
. But this will:
produce(state, (draftState) => {
draftState.burgers = draftState.burgers.filter(el => el.id !== action.payload)
})
Source: stackoverflow.com
Related Query
- How to remove elements from array using redux, immer, react
- How remove item from redux state using react hooks
- how to remove number from array of numbers using TypeScript and React
- How to map array response coming from the api using redux in react js in react js.?
- React JS: how to properly remove an item from this.state.data where data is an array of objects
- How to delete object from array using object property - React
- How to execute store.unsubscribe from useEffect using React hooks and Redux
- How can I cache data that I already requested and access it from the store using React and Redux Toolkit
- How to connect each element of array individually by using react redux
- How can I show certain elements from an array based on a React State?
- How to remove an element from an array that is inside an object in React JS (ES6)
- how to pass the current item to the function so that i can remove it from array in react component?
- Using React state, how can I remove markers from a Google map before adding new ones?
- How to remove selected index of an array from the DOM and reflect the change in React state?
- How to update redux state using a react variable passed up to the component from a child
- How to remove item from a generic Array in React Typescript?
- How to remove an array from another array in redux state javascript
- Material React Select Multiple: How i can remove from my array when i click in a selected element?
- How to remove value from array using index (Ant Design specific)?
- How to pass props from container component to redux form(component) - react using typescript
- How to remove all next elements from array in javascript or lodash
- How can I remove array from end singly using setState?
- How to remove item from an array through index in React
- How to remove a single object from Array Properties in React Js?
- How To Send Array of Object using FormData() From React Js To Nodejs, MongoDB?
- How to get the data from Redux store using class components in React
- How to update the global state using redux and remove an item from the global state
- How do I stop state store data from accumulating in a redux component every time I navigate to it using react router
- How to send an array as JSON from java servlet to react frontend using fetch()?
- How do I display data from api using react and redux
More Query from same tag
- props is not sending data to another component
- How to draw multiple Rectangle inside SVG
- How do you pass data to react components from express or koa without renderToString?
- How can i do shape.preventDefault(true); in react-konva
- How to force override an existing type in Typescript?
- Programmatically set value in material-ui Autocomplete TextField
- How do i deploy a React app to Github Pages from Github Actions?
- How to simulate a click on a Font Awesome Icon using Jest?
- images being duplicated when navigating between pages in redux / react application
- Passing function to a react class
- React JS Reusable Collapse/Toggle Function
- How to get query parameters in reactjs
- React Select Tag :: changing select options based on another select
- React Material UI, Card Spacing Issue
- React, setting onClick in html via dangerouslySetInnerHTML
- How to display data from JSON as flex row in div ReactJS
- jest test call of method that is not mocked
- React state updating through child component
- React Material UI Grid oversize full screen
- Superagent & Fetch returning promises -- How to handlle these?
- React state not getting updated in function call
- Get wrapper DOM element attributes from a method in React
- Can anyone provide an example on React-Redux Jest testing?
- How To Set pageProps Property In Next.js Page?
- passing the value from one component to another React
- Reducer not connected to redux state
- How to render JSON data as fields in the UI
- react bootstrap modal not showing
- Cycling through count in React component
- Error while trying to install Babel JSX precompiler