Skip to content

Commit

Permalink
docs: Update example-setstate.mdx (#833)
Browse files Browse the repository at this point in the history
Moved id generation for new todos out of reducers to keep them pure
  • Loading branch information
Vladyslav-Murashchenko authored Aug 4, 2021
1 parent 648d39b commit 1195510
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions website/docs/example-setstate.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ const TodoList = () => {
break
case "add":
draft.push({
id: "todo_" + Math.random(),
id: action.id,
title: "A new todo",
done: false
})
Expand All @@ -163,7 +163,8 @@ const TodoList = () => {

const handleAdd = useCallback(() => {
dispatch({
type: "add"
type: "add",
id: "todo_" + Math.random()
})
}, [])

Expand All @@ -189,7 +190,7 @@ const TodoList = () => {
break;
case "add":
draft.push({
id: "todo_" + Math.random(),
id: action.id,
title: "A new todo",
done: false
});
Expand Down Expand Up @@ -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
})
Expand Down

0 comments on commit 1195510

Please sign in to comment.