score:2
Accepted answer
first you have a typo and second you're not checking if the movie's id is not equal to current loops item id.
// item.id !== movie.id
const del = this.state.movies.filter(item => item.id !== movie.id);
// movies not movie
this.setstate({
movies: del
})
also don't ever use index as key in production (unless the items are static), it's an anti-pattern. instead, use the unique id <tr key={movie.id}>
score:0
in your handledelete function
handledelete= movie=>{
const del=this.state.movies.filter(item => item !== movie.id);
this.setstate({
movie:del <=== movies not movie!
})
console.log("clicked")
}
i think you just typo'd movie instead of movies when setting state
Source: stackoverflow.com
Related Query
- Unable to delete item from an array in React
- How to delete an item by index from a state array in React
- How to delete item from an array by onPress event in react
- React : Delete item from array
- 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
- Remove item from array in React
- React native delete multiple items from state array
- Delete an Item from Array not Rendering ReactJS Hooks
- Unexpected behavour when removing an item from an array in React
- Unable to set props values after delete the record from the list in React context API
- how to pass the current item to the function so that i can remove it from array in react component?
- How to delete objects from react state hook array with a button click
- Render item from an array after a fixed interval in React
- Cannot delete Item from Todo-list in React
- array of selected values which I want to delete from state is not working as expected - React
- Error rendering item from state array in React
- How to remove item from a generic Array in React Typescript?
- Unable to save to array React state from the response from the server
- Delete last item from array with useState
- How to filter item from array in React if their length is less than a certain number?
- Delete item from list not rendering react js
- How to remove item from an array through index in React
- How to delete an item from state in React
- Delete item from array in state in a child component
- Deleting item from state array in react
- Is there a way I can use button in react to delete a item in an array that is stored in the state
- using .filter to delete an item from an array of objects with react/javascript
- React Redux deleting item from array at specific index
- can anyone tell me why i am unable to delete an item from the todo list?
More Query from same tag
- Inline style is not working ReactJS
- Gutenberg block have to be resolved to display the right editing view
- Reading .md in React.js
- Api call fills one array but not the other?
- Redirect/ Routing issues in React and Express
- React update only one object of the state
- nav links are hidden - react
- nextjs RangeError: Maximum call stack size exceeded
- Execute Jquery in React Portals
- Have scrollable div fill up the above of BottomNavigation bar?
- How do i implement dark mode using states and save the setting to my localstorage?
- Strategy for Pinterest Product Hunt style modals and routing
- how can put ref to props.children
- I am learing react.js but i am finding it difficult to understand how the react app will work when deployed?
- React redux dispatch action to connect to mqtt
- Show Dialog on React material-ui
- Converting 'Enter' key event into a empty string or null in react
- Why is toggle todo not working in Redux?
- react-redux ssr async api call not working as expected
- undefined fetching data from firebase
- Creating a sortable table (with React.js) that was produced using Flask and Bootstrap
- Cant type in material ui Textfield (react)
- React Routing Menu - data handling best practice
- Cant disable X-Powered-By: Express
- Why search query params does not get the first chosen option
- How to use jest mockImplemention for default export module?
- nested routes with optional parameter
- boolean state variable change causes parent component to disappear?
- How to set 2 states asynchronously in React using useState
- Firebase onCreate add custom claims to the auth.user