Skip to content
Myr

docs: show todo.done in useImmer checkbox example (#1275)

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

The linked CodeSandbox used todo.finished for checked while the state uses done. Inline the full example with checked={todo.done} instead.

authored by Hashim Khan · committed by GitHub · parent b00474e · Browse files · 2 files+40 added−6 removed
This commit

State

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

Diff stats

2 files+40 added−6 removed

  • other:+40 added−6 removed

2 files+40 added−6 removed

modified:website/docs/example-setstate.mdx+20 added-3 removed
115 unmodified lines
116 });117 });118 }, []);119120 // etc120 return (121 <ul>122 {todos.map((todo) => (123 <li key={todo.id}>124 <label>125 <input126 type="checkbox"127 checked={todo.done}128 onChange={() => handleToggle(todo.id)}129 />130 {todo.title}131 </label>132 </li>133 ))}134 <button type="button" onClick={handleAdd}>135 Add todo136 </button>137 </ul>138 );139};140```141123For the full demo see [CodeSandbox](https://codesandbox.io/s/use-immer-bvd5v?file=/src/index.js).124142## useReducer + Immer143144Similarly to `useState`, `useReducer` combines neatly with Immer as well, as demonstrated in this [CodeSandbox](https://codesandbox.io/s/immer-usereducer-bqpzn?file=/src/index.js:0-1018):145
112 unmodified lines
modified:website/i18n/zh-CN/docusaurus-plugin-content-docs/current/example-setstate.mdx+20 added-3 removed
115 unmodified lines
116 });117 });118 }, []);119120 // etc120 return (121 <ul>122 {todos.map((todo) => (123 <li key={todo.id}>124 <label>125 <input126 type="checkbox"127 checked={todo.done}128 onChange={() => handleToggle(todo.id)}129 />130 {todo.title}131 </label>132 </li>133 ))}134 <button type="button" onClick={handleAdd}>135 Add todo136 </button>137 </ul>138 );139};140```141123完整的 demo 请参阅 [CodeSandbox](https://codesandbox.io/s/use-immer-bvd5v?file=/src/index.js)124142## useReducer + Immer143144与 `useState` 类似,`useReducer` 也与 Immer 巧妙结合,如 [CodeSandbox](https://codesandbox.io/s/immer-usereducer-bqpzn?file=/src/index.js:0-1018) 所示:145
112 unmodified lines