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

176
Views
Antd item.list removes always removes first last element

Hi there I made simple antd list where user can add, remove edit list. But the problem is that when i add, edit list verything works as it should. But when i remove item from a list, antd always remove last item from a list. Although i can remove any item.

  const [employeeList, setEmployeeList] = useState([])
    <List
      dataSource={employeeList}
      renderItem={(item, index) => (
       <List.Item id='listItem' >
         <Input 
          id='listItem-input'
          defaultValue={item.name} 
          onChange={(i) => {
            employeeList[index].name = i.target.value
            setEmployeeList(answerList)   
          }}
        />
        <span className='removeItem' 
          onClick={() => {
            let newList = setEmployeeList
            newList[index] = undefined
            setEmployeeList(newList.filter(e => e))
           }}
         >
           <CloseOutlined/>
         </span>
       </List.Item>
     )}
  />

I checked in console items in state gets removed, although it still stays in item.list

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

0

First of all I would recomend deleting items with splice()

so rather then this 3 lines in onClick (in remove) just

employeeList.splice(index,1)

Edit:

With your approach you probably want:
 let newList = employeeList
 newList[index] = undefined
about 4 years ago · Juan Pablo Isaza Report

0

Turns out i had to use a keys. List.Item wasn't registering changes without keys and was just deleting last item, on any change.

<List.Item id='listItem' key={item.answer} >
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!