score:0
You need to pass the ticketID
to your IconButton
's onClick
handler:
<IconButton
onClick={() => removeTicket(row.ticketID)}
aria-label="delete"
color="primary"
>
<DeleteIcon />
</IconButton>
And update your handler where you can create a new array using the .filter()
method:
const removeTicket = (ticketID)=> {
setRows(rows.filter(item => ticketID !== item.ticketID)
}
This rows.filter()
returns every element where the ticketID
is not the same as the one you passed down.
score:0
If you know index that will be removed you can use Array.prototype.slice
and
the logic is disconsider the element at index.
So, you will have to add the index
as second param in your map function and change the onClick
on IconButton
to () => removeTicket(index)
.
Your remove function will contains the following snippet:
setRows(prevRows => [
...prevRows.slice(0, index),
...prevRows.slice(index + 1)
]);
If you need the ticketId to make a call to an api you can get it through index rows[index]
or by passing it in the onClick function () => removeTicket(row.ticketID, index)
Source: stackoverflow.com
Related Query
- Remove a specific item from an array of objects Reactjs
- React JS: how to properly remove an item from this.state.data where data is an array of objects
- how to remove duplicate objects from an array in reactjs
- ReactJS - How to remove an item from an array in a functional component?
- Reactjs formik remove item from an array
- ReactJs Redux: how to remove duplicate objects (with duplicate values) from an array when deciding redux state (after map, filter, etc. functions)?
- How to remove one item from an array using filter() in ReactJS - function not working properly
- Remove item from objects array
- Remove the checked item from the checkbox array in Reactjs
- ReactJs : How to display a specific data of an object from an array of objects with a click
- Remove item from String Array ReactJS
- What's the advantage of using $splice (from immutability-helper) over filter to remove an item from an array in React?
- Remove item from an array (useState Hook)
- Remove item from array in React
- Create nested JSX list items from multi-level nested array of objects reactjs
- Remove item by key/value from Firestore array
- Why not to use splice with spread operator to remove item from an array in react?
- Remove item from array in redux
- reactjs - Render single icon on hover for list item rendered from array
- Adding key value pair (value from an array) to specific objects in an array
- Delete an Item from Array not Rendering ReactJS Hooks
- How to find length of an array of objects from ReactJS setState?
- How to correctly add and remove specific items from an array within state?
- Remove element of an object from array of objects - react state
- how to pass the current item to the function so that i can remove it from array in react component?
- Remove an item from local storage in reactjs
- useState remove item from array
- ReactJS / Javascript How to remove the duplicate array from multi dimentional array?
- Remove duplicates from NESTED array of objects
- Remove item from array if it already exists
More Query from same tag
- Axios POST does not recognize the data being passed in from react
- React: Use this.props.children or pass components as named props
- bad auth : Authentication failed
- React ES6 class method does not render into html table but outside it. Why?
- Can I get a reference to jsx react component so I can I forceUpdate/rerender react component from the chrome developer console?
- How to Pass properties from array of objects to api request
- Can't sort Column in Ant Design Table in Gatsby site
- Test mousedown event
- Deploying to Heroku with Webpack
- React : How can I not put basename for only one route?
- An import path cannot end with a '.tsx' extension
- Implement pagination for React Material table
- Cannot import Drawer component from antd react library
- What is wrong with my attempt to make React Smooth-Scrolling work?
- Use Material UI autocomplete in freeSolo mode with react-hook-form
- How to send date to child components in next using getStatisticProps?
- how to use howler.js in react?
- Trying to show only one form
- Persists react state when navigating to different pages using localStorage
- How do React Portals preserve Context from Providers in a different subtree?
- React component async await in other funtion
- Splitting the date and time into two lines in javascript
- Google Maps Api cannot call function inside dragend event
- agGrid - How to hide dynamically generated column
- how to import Helper class in react
- How can I access the React router's location prop?
- process.env is undefinined and I cannot read variable from it
- TypeError: Cannot read property 'addContact' of undefined onSubmit
- Getting latest state value with React Hook?
- Toggle Password Visibility for multiple password inputs