score:3
Accepted answer
the return value of the splice
method are the elements removed from the original array, not the array without the removed elements. i think the splice method is working just fine, you are using it wrong.
you shouldn't use splice
in a variable handled by usestate
cause splice
changes the original array. you should copy it and then set it:
const deletetodo = (todo) => {
const aux = [...todos];
aux.splice(todo, 1);
settodos(aux);
};
Source: stackoverflow.com
Related Query
- Reduce not removing correct array item
- Unexpected behavour when removing an item from an array in React
- React: How to update an item in array without removing all the other props?
- onClick event only leaves the last item of the DOM array instead of removing the target
- Array splice removing wrong item or multiple ones at once
- How to filter item from array in React if their length is less than a certain number?
- Reactjs - adding a read more button to an array to hide/show more than 3 items
- Removing an item from an array of items only removes the last item
- Array filter with more than one element
- React holds state of no more than one array element
- Performing state and array manipulation more than once by passing props only once
- React hooks removing item from an array and add it to another array
- React add more than one photo in array
- Removing specific item from nested array and saving the result, how to make this code cleaner
- Reactjs map function mapping more elements than the ones present in array
- Removing item from an array of items does not work
- Filtering js array of objects based on more than one property
- Array.splice(index, 1) removing more than 1 item?
- Removing item from array - Parent Child - React Hooks
- Removing Item from API / Array in reactJS
- removing an item from an array in ReactJS
- React/Material-UI: How can I map multiple tables from a JSON object with more than one array of data?
- Reduce an array based on more than one value
- React: Updating array inside State with spread operator returns 1,000X more results than needed
- Removing children from Array inside ScrollView always deletes last item
- Removing an specific item from an array in React
- React - reset state to empty array if more than 2 items selected
- How to show more than one item in react
- React js removing item from paginated array won't update the array unless the page changes
- When I click the button more than once, array gets a value. I want it to take all values in the function
More Query from same tag
- Material-UI: Add an icon to TextField
- Don't trigger onChange if same option is selected in react-select
- onPageSizeChange in react gives old value
- Switch-case statement destroys rendered components
- Why can't I pass general JSX to a wrapped component in react?
- How can I groupby in React/Redux code (new to frontend)?
- Mutating state from React's useState hook
- react-styled-flexboxgrid different config for different viewport
- TypeError: undefined is not an object (evaluating 'this.localVideoref')
- history.push with Logout Icon
- Redux is not updating component even after returning new state object
- hide/show clicking on another div
- How to check if image is not vallid in react?
- Simplifying onClick function prop
- What's hydrate action in Next Redux Wrapper?
- Why is my redux app not caching an async api call in redux-thunk?
- How to trick react router into thinking `/` is the mount directory?
- Redirect To Route within Function React Router Dom
- useState and useEffect in terms of Firestore function
- global.location not working in Jest tests
- ReactJS showing div element on click
- Updating list with state React
- How to fix, does not wait for a respons, but begin to render
- handleChange event does not match the data in local storage
- How to toggle using redux in react for a nested link component within a mobile menu
- Firebase Auth - User not logged in after Firebase sign up and redirect
- Radio button checked property not called from Button in a List
- How to implement a horizontal scrollview like an appstore
- load json with reactjs
- Express Js is unable to retrieve submitted form data from React Js