From 6e12b4bd931796ef85e6e82a76e55f764a06b3b3 Mon Sep 17 00:00:00 2001
From: Agata Talita <63733780+agatatalitatest@users.noreply.github.com>
Date: Wed, 8 Dec 2021 02:36:01 +0100
Subject: [PATCH 01/13] Change setState to use function with prev state
To have an example that reminds about best practices.
https://reactjs.org/docs/state-and-lifecycle.html#state-updates-may-be-asynchronous
---
content/docs/hooks-intro.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/content/docs/hooks-intro.md b/content/docs/hooks-intro.md
index ded29158745..715d0df45f6 100644
--- a/content/docs/hooks-intro.md
+++ b/content/docs/hooks-intro.md
@@ -17,7 +17,7 @@ function Example() {
return (
You clicked {count} times
-
From d5d57ac5f3203f66b8df952bab784b7a1cbe0f6c Mon Sep 17 00:00:00 2001
From: Agata Talita <63733780+agatatalitatest@users.noreply.github.com>
Date: Wed, 8 Dec 2021 02:45:30 +0100
Subject: [PATCH 02/13] Change setState to use function with prev state
To have an example that reminds about best practices.
https://reactjs.org/docs/state-and-lifecycle.html#state-updates-may-be-asynchronous
---
content/docs/hooks-intro.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/content/docs/hooks-intro.md b/content/docs/hooks-intro.md
index 715d0df45f6..ab04120a0f9 100644
--- a/content/docs/hooks-intro.md
+++ b/content/docs/hooks-intro.md
@@ -17,7 +17,7 @@ function Example() {
return (
You clicked {count} times
- setCount(previousCout + 1)}>
+ setCount(previousCount + 1)}>
Click me
From 2d8144931ed7d26a1fc42b44f32f45d3d3a06bf4 Mon Sep 17 00:00:00 2001
From: Agata Talita <63733780+agatatalitatest@users.noreply.github.com>
Date: Wed, 8 Dec 2021 02:45:53 +0100
Subject: [PATCH 03/13] Change setState to use function with prev state
To have an example that reminds about best practices.
https://reactjs.org/docs/state-and-lifecycle.html#state-updates-may-be-asynchronous
---
content/docs/hooks-overview.md | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/content/docs/hooks-overview.md b/content/docs/hooks-overview.md
index d299a8b6d95..021bac3fe1c 100644
--- a/content/docs/hooks-overview.md
+++ b/content/docs/hooks-overview.md
@@ -30,7 +30,7 @@ function Example() {
return (
You clicked {count} times
- setCount(count + 1)}>
+ setCount(previousCount + 1)}}>
Click me
@@ -91,7 +91,7 @@ function Example() {
return (
You clicked {count} times
- setCount(count + 1)}>
+ setCount(previousCount + 1)}}>
Click me
From 5231e5714d644ffc331e41534e7f2c33055028f5 Mon Sep 17 00:00:00 2001
From: Agata Talita <63733780+agatatalitatest@users.noreply.github.com>
Date: Wed, 8 Dec 2021 02:56:08 +0100
Subject: [PATCH 04/13] Change setState to use function with prev state
To have an example that reminds about best practices.
https://reactjs.org/docs/state-and-lifecycle.html#state-updates-may-be-asynchronous
---
content/docs/hooks-intro.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/content/docs/hooks-intro.md b/content/docs/hooks-intro.md
index ab04120a0f9..987696bed49 100644
--- a/content/docs/hooks-intro.md
+++ b/content/docs/hooks-intro.md
@@ -17,7 +17,7 @@ function Example() {
return (
From f94cce1a28ba98636d97f6552bc680e5f1d48314 Mon Sep 17 00:00:00 2001
From: Agata Talita <63733780+agatatalitatest@users.noreply.github.com>
Date: Wed, 8 Dec 2021 03:08:08 +0100
Subject: [PATCH 05/13] Change setState to use function with prev state
To have an example that reminds about best practices.
https://reactjs.org/docs/state-and-lifecycle.html#state-updates-may-be-asynchronous
---
content/docs/hooks-effect.md | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/content/docs/hooks-effect.md b/content/docs/hooks-effect.md
index 86b3b6649b0..dc7178c1a84 100644
--- a/content/docs/hooks-effect.md
+++ b/content/docs/hooks-effect.md
@@ -25,7 +25,7 @@ function Example() {
return (
@@ -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}
- setCount(count + 1)}>
+ setCount(prevCount => prevCount + 1)}>
Click me
```
@@ -204,7 +204,7 @@ Let's now **recap what we learned line by line** and check our understanding.
6: return (
7:
- setCount(count + 1)}>
+ setCount(prevCount => prevCount + 1)}>
Click me
From 9509f2173bc2510f36d2a6b72ea6d94df3c31c52 Mon Sep 17 00:00:00 2001
From: Agata Talita <63733780+agatatalitatest@users.noreply.github.com>
Date: Wed, 8 Dec 2021 03:43:07 +0100
Subject: [PATCH 12/13] Update hooks-overview.md
---
content/docs/hooks-overview.md | 3 +++
1 file changed, 3 insertions(+)
diff --git a/content/docs/hooks-overview.md b/content/docs/hooks-overview.md
index c23cae61791..9873d352538 100644
--- a/content/docs/hooks-overview.md
+++ b/content/docs/hooks-overview.md
@@ -42,6 +42,9 @@ 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 the value we want to set with `setCount` function.
+
#### Declaring multiple state variables {#declaring-multiple-state-variables}
You can use the State Hook more than once in a single component:
From 03160c0e8e6b4e5d712eea1e83ee5b8d538f5efa Mon Sep 17 00:00:00 2001
From: Agata Talita <63733780+agatatalitatest@users.noreply.github.com>
Date: Wed, 8 Dec 2021 03:46:23 +0100
Subject: [PATCH 13/13] Update hooks-overview.md
---
content/docs/hooks-overview.md | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/content/docs/hooks-overview.md b/content/docs/hooks-overview.md
index 9873d352538..699ef034d60 100644
--- a/content/docs/hooks-overview.md
+++ b/content/docs/hooks-overview.md
@@ -42,8 +42,9 @@ 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 the value we want to set with `setCount` function.
+>
+> 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}