score:3
Accepted answer
this.todosRef.on('child_removed', snapshot => {
this.setState(previousState => {
const todos = previousState.todos.filter(todo => todo.key !== snapshot.key);
return { todos };
});
});
score:2
this.todosRef.on('child_removed', snapshot => {
const removedTodo = {
key: snapshot.key,
value: snapshot.val()
}
const index = this.state.todos.indexOf(removedTodo);
let todos = this.state.todos.splice(index, removedTodo);
todos.splice(index, 1);
this.setState({
todos: todos
});
});
Source: stackoverflow.com
Related Query
- Setting state without a removed item
- Replace array item with another one without mutating state
- Removing item in nested state results in incorrect item being removed in DOM
- Set State Item Back to Initial State without mutation
- Setting active state on a Nav item depending on the Route using ReactBootstrap
- Setting context state with vs without constructor
- Is it possible to add item to a react array state without re-rendering all items?
- Setting state without re-rendering with useEffect not working
- How to update an item in array while setting state in react
- How to execute change in a component without setting state in a react app?
- Setting the state on one item only
- setState removes an items from an array using filter but removed item stays in state as an empty string
- Setting React state in .map function without overwriting state
- React Setting State to Scope of Item
- React State changing to false automatically without setting it
- How to manage state of many dynamic variables without manually setting each and every variable on my own
- React.js - Setting a state item as an Array item, referencing in other state items then updating state when Array Item changes
- How to delete an item from state array?
- Setting state on componentDidMount()
- React: update one item in a list without recreating all items
- How to edit an item in a state array?
- React: setting the disabled attribute based on a state
- Delete an item from Redux state
- Typescript and React setting initial state with empty typed array
- React hook equivalent to callback function after setting state
- How to update react state without re-rendering component?
- Setting state in the Query component of react-apollo
- init state without constructor in react
- React: Setting state to an es6 Map
- semantic ui react Setting dropdown value to state
More Query from same tag
- ReactJS: map json and return to Table
- How to customize mui daterange with styled components
- filter array of objects not returning filtered values
- MUI - Slow makeStyles if using props in methods
- How to conditionally show element in react JSX?
- How to change default behavior of components from Material UI
- Object.Array.map is undefined ReactJS component MERN Stack
- How to remove item from a generic Array in React Typescript?
- How do you configure a react app to use typescript?
- Display only one row and hide others in CSS Grid
- Module not found: Error: Can't resolve './App' from React 18 w/TypeScript
- How to animate UI in react?
- How to add multiple onClick function on a button in ReactJS
- React pass props when child component is a variable
- How to disable the react leaflet zoom
- React useEffect does not re-render after sorting entries
- React Native focus not changed in tvOS
- Why am I getting error while adding service in EmailJS?
- 'AADSTS500011' error message returned from API call using adalFetch
- Can you access event data from i element onclick?
- Why ReactJs says the link or path is broken when I put it in Card.img#src?
- TypeScript: is there a way to parameterize an enum
- Module not found in React
- best practise with optional parts on html rendering
- React onSubmit Button To POST Not Working
- How to navgiate to a new page using react router dom with typescript
- what does <{}> mean at the end of extension in javascript?
- Unable to filter properly data in react js table based on field?
- How do I push items or maybe add an element in array of array
- Attach element to arrow function