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

100
Views
How to click on the button will show an item

react I wish clicking a button would reduce an item, but clicking a button would do nothing ... please help me...

 const [cars, setCars] = useCars([])

 const handleDelete = id => {
      const remaining = cars.filter(car => car._id !== id);
      setCars(' ');
 }
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

please check this i have written sample code

import React, { useState } from 'react';

export default function App() {
  const [lists, setLists] = useState([]);

  const remove = (index) => {
    // REMOVING THE RECORD BASED ON THE PREVIOUS STATE VALUE - ON THE GIVEN INDEX
    setLists((v) => {
      const a = [...v];
      a.splice(index, 1);
      return [...a];
    });
  };

  // FOR ADDING SAMPLE DATA
  const addList = () => {
    setLists((v) => [...v, { name: 'List data ' + lists.length }]);
  };

  return (
    <div>
      <button onClick={addList}>Add List</button>
      <ul>
        {lists.map((e, k) => (
          <li key={k}>
            {e.name} <button onClick={(k) => remove(k)}>Remove</button>{' '}
          </li>
        ))}
      </ul>      
    </div>
  );
}
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!