Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

212
Visualizações
Changing the list of items doesn't rerender the component when using react-beautiful-dnd

I'm using react-beautiful-dnd to let the user choose the options using drag and drop.

However, the component doesn't seem to re-render when the order of the options is changed. (I've tried console logging it, and it appears to have changed.)

This is the onDragEnd method:

const onDragEnd = (result) => {
    if (!result.destination) return;

    const { source, destination } = result;

    if (!destination) {
      return;
    }

    if (source.index === destination.index) {
      return;
    }

    let items = [...list];
    const [removed] = items.splice(source.index, 1);
    items.splice(destination.index, 0, removed);

    setList([...items]);
  };

All the code can be found in this codesandbox.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You are rendering optionalCourses in the DND but you are updating the list state. You should render the list instead.

return (
    <div className={componentClassName}>
      <span className={`${componentClassName}__title`}>{groupTitle}</span>
      <DragDropContext onDragEnd={onDragEnd}>
        <Droppable droppableId={groupId}>
          {(provided, snapshot) => (
            <div
              {...provided.droppableProps}
              ref={provided.innerRef}
              className={`${componentClassName}__list`}
            >
              

>  {list.map((optionalCourse, index) => {
>                      return <OptionalCourseCard key={index} {...optionalCourse} />;

              })}
              {provided.placeholder}
            </div>
          )}
        </Droppable>
      </DragDropContext>
    </div>
  );
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda