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

206
Views
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 answers
Answer question

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 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!