From 2a8c4a53b31f96236f5350d669d133de79b7053a Mon Sep 17 00:00:00 2001 From: Deniz Susman Date: Fri, 8 Feb 2019 16:24:23 +0300 Subject: [PATCH 1/3] Typo fix in blog content (#1651) "Recommendation" instead of "Recomendation". --- content/blog/2018-06-07-you-probably-dont-need-derived-state.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/content/blog/2018-06-07-you-probably-dont-need-derived-state.md b/content/blog/2018-06-07-you-probably-dont-need-derived-state.md index 7709054b8..6949be3ec 100644 --- a/content/blog/2018-06-07-you-probably-dont-need-derived-state.md +++ b/content/blog/2018-06-07-you-probably-dont-need-derived-state.md @@ -213,7 +213,7 @@ To recap, when designing a component, it is important to decide whether its data 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. For **uncontrolled** components, if you're trying to reset state when a particular prop (usually an ID) changes, you have a few options: -* **Recomendation: To reset _all internal state_, use the `key` attribute.** +* **Recommendation: To reset _all internal state_, use the `key` attribute.** * Alternative 1: To reset _only certain state fields_, watch for changes in a special property (e.g. `props.userID`). * Alternative 2: You can also consider fall back to an imperative instance method using refs. From 741dc3b5f1b83b793b725edec2b1ef88c9181c44 Mon Sep 17 00:00:00 2001 From: Dan Abramov Date: Fri, 8 Feb 2019 20:16:30 +0000 Subject: [PATCH 2/3] Just throw --- content/docs/hooks-reference.md | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/content/docs/hooks-reference.md b/content/docs/hooks-reference.md index 90091d8d1..7a3a0dde8 100644 --- a/content/docs/hooks-reference.md +++ b/content/docs/hooks-reference.md @@ -246,9 +246,7 @@ function reducer(state, action) { case 'reset': return init(action.payload); default: - // A reducer must always return a valid state. - // Alternatively you can throw an error if an invalid action is dispatched. - return state; + throw new Error(); } } From e3cf542e75018ff7f0104ab7a4df9dc2b8d43bef Mon Sep 17 00:00:00 2001 From: Dan Abramov Date: Fri, 8 Feb 2019 20:37:28 +0000 Subject: [PATCH 3/3] Fix line numbers --- content/docs/hooks-reference.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/content/docs/hooks-reference.md b/content/docs/hooks-reference.md index 7a3a0dde8..dac51b17a 100644 --- a/content/docs/hooks-reference.md +++ b/content/docs/hooks-reference.md @@ -232,7 +232,7 @@ You can also create the initial state lazily. To do this, you can pass an `init` 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: -```js{1-3,11-12,21,26} +```js{1-3,11-12,19,24} function init(initialCount) { return {count: initialCount}; }