From fbd1ffd84af8aeb49205e6eda050ad2ba41d3582 Mon Sep 17 00:00:00 2001 From: myNameIsDu Date: Sun, 23 Oct 2022 04:12:43 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E5=88=A0=E9=99=A4?= =?UTF-8?q?=E4=B9=8B=E5=90=8E=E6=B7=BB=E5=8A=A0=E8=BF=98=E5=9C=A8=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/comonent/dish-list.tsx | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/app/comonent/dish-list.tsx b/app/comonent/dish-list.tsx index 87afd38..22d4ccf 100644 --- a/app/comonent/dish-list.tsx +++ b/app/comonent/dish-list.tsx @@ -1,8 +1,9 @@ -import { useState, Fragment, type MouseEvent } from "react"; +import { useState, Fragment, type MouseEvent, useRef } from "react"; interface DishesListPropsType { dishes: string[]; } export function DishesList({ dishes }: DishesListPropsType) { + const dishesRef = useRef([...dishes]); const [list, setList] = useState(() => { if (dishes.length) { // 根据 dishes 长度生成 [0,1,2,3] 的 list @@ -18,6 +19,7 @@ export function DishesList({ dishes }: DishesListPropsType) { const newList = [...list]; index && newList.splice(Number(index), 1); setList(newList); + index && dishesRef.current.splice(Number(index), 1); } }; const handleAdd = () => { @@ -33,7 +35,7 @@ export function DishesList({ dishes }: DishesListPropsType) { option