Skip to content
Myr

docs: Update example-setstate.mdx (#833)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Moved id generation for new todos out of reducers to keep them pure

authored by VladislavMurashchenko · committed by GitHub · parent 648d39b · Browse files · 1 file+5 added−4 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+5 added−4 removed

  • other:+5 added−4 removed

1 file+5 added−4 removed

modified:website/docs/example-setstate.mdx+5 added-4 removed
138 unmodified lines
139 todo.done = !todo.done140 break141 case "add":142 draft.push({143 id: "todo_" + Math.random(),143 id: action.id,144 title: "A new todo",145 done: false146 })147 break
14 unmodified lines
162 }, [])163164 const handleAdd = useCallback(() => {165 dispatch({166 type: "add"166 type: "add",167 id: "todo_" + Math.random()168 })169 }, [])170171 // etc
17 unmodified lines
189 todo.done = !todo.done;190 break;191 case "add":192 draft.push({192 id: "todo_" + Math.random(),193 id: action.id,194 title: "A new todo",195 done: false196 });197 break;
29 unmodified lines
227 todo.done = !todo.done228 break229 case "add":230 draft.push({230 id: "todo_" + Math.random(),231 id: action.id,232 title: "A new todo",233 done: false234 })235 break
5 unmodified lines