From 2569c0a6db5e369c1c6bb60c13122e4c1cbb388b Mon Sep 17 00:00:00 2001 From: VladislavMurashchenko <35494518+VladislavMurashchenko@users.noreply.github.com> Date: Fri, 30 Jul 2021 18:53:24 +0300 Subject: [PATCH] Update example-setstate.mdx Moved id generation for new todos out of reducers to keep them pure --- website/docs/example-setstate.mdx | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/website/docs/example-setstate.mdx b/website/docs/example-setstate.mdx index 59f3913c..dc32578a 100644 --- a/website/docs/example-setstate.mdx +++ b/website/docs/example-setstate.mdx @@ -140,7 +140,7 @@ const TodoList = () => { break case "add": draft.push({ - id: "todo_" + Math.random(), + id: action.id, title: "A new todo", done: false }) @@ -163,7 +163,8 @@ const TodoList = () => { const handleAdd = useCallback(() => { dispatch({ - type: "add" + type: "add", + id: "todo_" + Math.random() }) }, []) @@ -189,7 +190,7 @@ const TodoList = () => { break; case "add": draft.push({ - id: "todo_" + Math.random(), + id: action.id, title: "A new todo", done: false }); @@ -227,7 +228,7 @@ const todosReducer = produce((draft, action) => { break case "add": draft.push({ - id: "todo_" + Math.random(), + id: action.id, title: "A new todo", done: false })