Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

153
Views
How to delete all rows on click in a dynamic table using reactjs

Currently when the delete button is clicked it only deletes one row at a time. However, my current aim is for it do delete all rows at the same time but I the solutions I have tried do not work. Here is the current code:

const [shop, setShop] = useState([]);
...
const [count, setCount] = useState(0);
...
const handleDelete = (shopsId) => {
        const newArr = [...shop];
        const index = shop.findIndex((shop) => shop.id === shopsId);
        newArr.splice(index, 1);
        setShop(newArr);
        setCount(count - count)
      }

This method is successful if I want to remove a specific row however I do not want to do this but instead remove all the rows ('delete all'). Any help would be appreciated.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

set it as empty array

setShop([ ])

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!