From 185903bbc806203d71e24671ee12cd4fb56f1fb2 Mon Sep 17 00:00:00 2001 From: 0xsuxin <709228919@qq.com> Date: Tue, 30 Jul 2024 12:02:01 +0800 Subject: [PATCH] task1: 0xsuxin --- members/0xsuxin/task1/src/components/ToDoList/index.tsx | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/members/0xsuxin/task1/src/components/ToDoList/index.tsx b/members/0xsuxin/task1/src/components/ToDoList/index.tsx index adf6d293b..1d7f5dc91 100644 --- a/members/0xsuxin/task1/src/components/ToDoList/index.tsx +++ b/members/0xsuxin/task1/src/components/ToDoList/index.tsx @@ -133,8 +133,14 @@ function ToDoList() { if (todoList?.length) { setData(todoList); } + const handle = () => { + setData((value) => { + store2('todoList', value); + }); + }; + window.addEventListener('beforeunload', handle); return () => { - store2('todoList', todoList); + window.removeEventListener('beforeunload', handle); }; }, []);