Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

177
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda