From 11955103ee6d63adc819438d76ac8a8585e1c44e Mon Sep 17 00:00:00 2001 From: VladislavMurashchenko <35494518+VladislavMurashchenko@users.noreply.github.com> Date: Wed, 4 Aug 2021 18:59:29 +0300 Subject: [PATCH] docs: Update example-setstate.mdx (#833) 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 })