Cannot assign to read only property 'tasks' of object '#<Object>'

Viewed 26

I have faced this error and I am trying Object.assign method but doesn't work How may I fixed this error

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

  // if the user drags and drops back in the same position
  if (
    destination.droppableId === source.droppableId &&
    destination.index === source.index
  ) {
    return;
  }

  if (source.droppableId !== destination.droppableId) {
    const sourceColIndex = data.findIndex(
      (e) => e.id.toString() === source.droppableId
    );
    const destinationColIndex = data.findIndex(
      (e) => e.id.toString() === destination.droppableId
    );

    const sourceCol = data[sourceColIndex];
    const destinationCol = data[destinationColIndex];

    const sourceTask = [...sourceCol.tasks];
    const destinationTask = [...destinationCol.tasks];

    const [removed] = sourceTask.splice(source.index, 1);
    destinationTask.splice(destination.index, 0, removed);

    data[sourceColIndex].tasks = sourceTask;
    data[destinationColIndex].tasks = destinationTask;

    addProjectData(data);

    // console.log(destinationTask);
    // console.log(destinationCol.id);
    // addProject({
    //   id: destinationCol?.id,
    //   data: {
    //     tasks: destinationTask,
    //   },
    // });
    // addProject({
    //   id: sourceCol?.id,
    //   data: {
    //     tasks: sourceTask,
    //   },
    // });
  }
};

I have faced this error and I am trying Object.assign method but doesn't work

Uncaught TypeError: Cannot assign to read only property 'tasks' of object '#<Object>'
0 Answers
Related