Skip to content

Commit 2c63890

Browse files
authored
Merge pull request reactjs#8 from reactjs/sync-e3cf542e
Sync with reactjs.org @ e3cf542
2 parents 0897c70 + 195f866 commit 2c63890

File tree

2 files changed

+3
-5
lines changed

2 files changed

+3
-5
lines changed

content/blog/2018-06-07-you-probably-dont-need-derived-state.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ To recap, when designing a component, it is important to decide whether its data
213213
Instead of trying to **"mirror" a prop value in state**, make the component **controlled**, and consolidate the two diverging values in the state of some parent component. For example, rather than a child accepting a "committed" `props.value` and tracking a "draft" `state.value`, have the parent manage both `state.draftValue` and `state.committedValue` and control the child's value directly. This makes the data flow more explicit and predictable.
214214

215215
For **uncontrolled** components, if you're trying to reset state when a particular prop (usually an ID) changes, you have a few options:
216-
* **Recomendation: To reset _all internal state_, use the `key` attribute.**
216+
* **Recommendation: To reset _all internal state_, use the `key` attribute.**
217217
* Alternative 1: To reset _only certain state fields_, watch for changes in a special property (e.g. `props.userID`).
218218
* Alternative 2: You can also consider fall back to an imperative instance method using refs.
219219

content/docs/hooks-reference.md

+2-4
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ You can also create the initial state lazily. To do this, you can pass an `init`
232232

233233
It lets you extract the logic for calculating the initial state outside the reducer. This is also handy for resetting the state later in response to an action:
234234

235-
```js{1-3,11-12,21,26}
235+
```js{1-3,11-12,19,24}
236236
function init(initialCount) {
237237
return {count: initialCount};
238238
}
@@ -246,9 +246,7 @@ function reducer(state, action) {
246246
case 'reset':
247247
return init(action.payload);
248248
default:
249-
// A reducer must always return a valid state.
250-
// Alternatively you can throw an error if an invalid action is dispatched.
251-
return state;
249+
throw new Error();
252250
}
253251
}
254252

0 commit comments

Comments
 (0)