Why i can’t edit my tasks after click in edition button in ReactJs? [closed]

I’m creating a list of tasks in ReactJs and I’m having a problem with editing the tasks, when I click on the edit button it simply deletes all the tasks, could anyone help me create the editing tasks?

here is the code I developed from the edition

import Box from '@mui/material/Box';
import TextField from '@mui/material/TextField';
import { type FormEvent, useEffect, useState } from 'react';
import { ToastContainer, toast } from 'react-toastify';
import CustomizedTables from '../table';
import { CirclePlus } from 'lucide-react';

export default function Body() {
  const [tasks, setTasks] = useState<any[]>([]);
  const [isEditingTask, setIsEditingTask] = useState(false);


  function saveTask(event: FormEvent<HTMLFormElement>) {
    event.preventDefault();

    const data = new FormData(event.currentTarget);
    const taskValue = data.get('task')?.toString().trim();
    if (!taskValue) {
      toast.error('Tarefa não inserida');
      return;
    }
    event.currentTarget.reset();
    setTasks([...tasks, taskValue]);
  }

  function deleteTask(taskToDelete: string) {
    const newTaskList = tasks.filter((task: string) => task !== taskToDelete);
    setTasks(newTaskList);
  }

  function editTask(taskToEdit: string) {
    setIsEditingTask(true);


    // the error occours below
    const editedTask = tasks.map((task: string) => {
      // eslint-disable-next-line @typescript-eslint/no-unused-expressions
      task === taskToEdit ? { ...tasks, isEditingTask: !isEditingTask } : tasks;
    });

    setTasks(editedTask);
  }

  return (
    <div>
      <div
        className="p-4 bg-white rounded-lg shadow sm:p-6 md:p-8
            mx-auto max-w-full size-max mt-8 outline outline-zinc-400"
      >
        <Box
          onSubmit={(event) => saveTask(event)}
          component="form"
          sx={{
            '& > :not(style)': { m: 1, width: '25ch' },
          }}
          noValidate
          autoComplete="off"
          className=" flex justify-center items-center mt-1"
        >
          <TextField
            id="outlined-basic"
            label="Adicione uma tarefa"
            variant="outlined"
            name="task"
          />
          <button type="submit" className="h-8 max-w-max py-0">
            <CirclePlus className="text-green-400 p-0" />
          </button>
        </Box>
        <CustomizedTables
          tasks={tasks}
          deleteTask={deleteTask}
          editTask={editTask}
        />
        <ToastContainer autoClose={3500} />
      </div>
    </div>
  );
}

here is the component that renders the tasks

import Paper from '@mui/material/Paper';
import Table from '@mui/material/Table';
import TableBody from '@mui/material/TableBody';
import TableCell, { tableCellClasses } from '@mui/material/TableCell';
import TableContainer from '@mui/material/TableContainer';
import TableHead from '@mui/material/TableHead';
import TableRow from '@mui/material/TableRow';
import { styled } from '@mui/material/styles';
import { FilePenLine, Trash2 } from 'lucide-react';
import * as React from 'react';

const StyledTableCell = styled(TableCell)(({ theme }) => ({
  [`&.${tableCellClasses.head}`]: {
    backgroundColor: theme.palette.common.black,
    color: theme.palette.common.white,
  },
  [`&.${tableCellClasses.body}`]: {
    fontSize: 14,
  },
}));

const StyledTableRow = styled(TableRow)(({ theme }) => ({
  '&:nth-of-type(odd)': {
    backgroundColor: theme.palette.action.hover,
  },
  // hide last border
  '&:last-child td, &:last-child th': {
    border: 0,
  },
}));
interface Task {
  tasks: string[];
  deleteTask: (taskToDelete: string) => void;
  editTask: (taskToEdit: string) => void;
}

export default function CustomizedTables({
  tasks,
  deleteTask,
  editTask,
}: Task) {
  return (
    <TableContainer component={Paper}>
      <Table sx={{ minWidth: 700 }} aria-label="customized table">
        <TableHead>
          <TableRow>
            <StyledTableCell>Tarefas</StyledTableCell>
            <StyledTableCell align="right">Ações</StyledTableCell>
          </TableRow>
        </TableHead>
        <TableBody>
          {tasks.map((task) => (
            <StyledTableRow key={task}>
              <StyledTableCell component="th" scope="row">
                <div className="text-base font-sans font-medium">{task}</div>
              </StyledTableCell>

              <StyledTableCell align="center">
                <div className="flex-1 justify-end flex space-x-2">
                  <button onClick={() => editTask(task)}>
                    <FilePenLine className="text-sky-700" />
                  </button>
                  <button onClick={() => deleteTask(task)}>
                    <Trash2 className="text-red-700" />
                  </button>
                </div>
              </StyledTableCell>
            </StyledTableRow>
          ))}
        </TableBody>
      </Table>
    </TableContainer>
  );
}

can you reproduce my scenario with the code in the sandbox:
https://codesandbox.io/p/github/TarsooPaulo/Lista-de-Tarefas/main?embed=1&file=%2Fsrc%2Fcomponents%2FBody%2Findex.tsx

5

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật