diff --git a/content/docs/hooks-effect.md b/content/docs/hooks-effect.md index 86b3b6649b0..311b60867e4 100644 --- a/content/docs/hooks-effect.md +++ b/content/docs/hooks-effect.md @@ -25,7 +25,7 @@ function Example() { return (

You clicked {count} times

-
@@ -74,7 +74,7 @@ class Example extends React.Component { return (

You clicked {this.state.count} times

-
@@ -106,7 +106,7 @@ function Example() { return (

You clicked {count} times

-
diff --git a/content/docs/hooks-faq.md b/content/docs/hooks-faq.md index 99473c7351f..204ed469ba3 100644 --- a/content/docs/hooks-faq.md +++ b/content/docs/hooks-faq.md @@ -138,7 +138,7 @@ function Example() { return (

You clicked {count} times

-
@@ -399,7 +399,7 @@ function Example() { return (

You clicked {count} times

-
diff --git a/content/docs/hooks-overview.md b/content/docs/hooks-overview.md index d299a8b6d95..699ef034d60 100644 --- a/content/docs/hooks-overview.md +++ b/content/docs/hooks-overview.md @@ -30,7 +30,7 @@ function Example() { return (

You clicked {count} times

-
@@ -42,6 +42,10 @@ Here, `useState` is a *Hook* (we'll talk about what this means in a moment). We The only argument to `useState` is the initial state. In the example above, it is `0` because our counter starts from zero. Note that unlike `this.state`, the state here doesn't have to be an object -- although it can be if you want. The initial state argument is only used during the first render. +> +> If you are wondering why we are passing a function to `setCount`, read more about [functional updates](//docs/hooks-reference.html#functional-updates) or [general good practices with updating component state](https://reactjs.org/docs/hooks-reference.html#functional-updates). +>In short, we can pass value or [special function](https://reactjs.org/docs/hooks-reference.html#functional-updates) that takes a previous state value and returns a new value we want to store in `count`. + #### Declaring multiple state variables {#declaring-multiple-state-variables} You can use the State Hook more than once in a single component: @@ -91,7 +95,7 @@ function Example() { return (

You clicked {count} times

-
diff --git a/content/docs/hooks-state.md b/content/docs/hooks-state.md index 0b4d15b65e7..2f13c917d6c 100644 --- a/content/docs/hooks-state.md +++ b/content/docs/hooks-state.md @@ -20,7 +20,7 @@ function Example() { return (

You clicked {count} times

-
@@ -47,7 +47,7 @@ class Example extends React.Component { return (

You clicked {this.state.count} times

-
@@ -174,7 +174,7 @@ In a function, we can use `count` directly: In a class, we need to call `this.setState()` to update the `count` state: ```js{1} - ``` @@ -182,7 +182,7 @@ In a class, we need to call `this.setState()` to update the `count` state: In a function, we already have `setCount` and `count` as variables so we don't need `this`: ```js{1} - ``` @@ -204,7 +204,7 @@ Let's now **recap what we learned line by line** and check our understanding. 6: return ( 7:
8:

You clicked {count} times

- 9: 12: