You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+9-9
Original file line number
Diff line number
Diff line change
@@ -612,7 +612,7 @@ Hide/Show table of contents
612
612
613
613
The usage ofError boundaries from the above library is quite straight forward.
614
614
615
-
>**_Note when using react-error-boundary:_** ErrorBoundary is a client component. You can only pass props to it that are serializeable or use it in files that have a `"use client";` directive.
615
+
>**_Note when using react-error-boundary:_** ErrorBoundary is a client component. You can only pass props to it that are serializable or use it in files that have a `"use client";` directive.
616
616
617
617
```jsx
618
618
"use client";
@@ -1254,7 +1254,7 @@ class ParentComponent extends React.Component {
1254
1254
1255
1255
30. ### Why React uses `className` over `class` attribute?
1256
1256
1257
-
The attribute names written in JSX turned into keys of JavaScript objects and the JavaScript names cannot contain dashes or reversed words, it is recommended to use camelCase whereever applicable in JSX code. The attribute `class` is a keyword in JavaScript, and JSX is an extension of JavaScript. That's the principle reason why React uses `className` instead of `class`. Pass a string as the `className` prop.
1257
+
The attribute names written in JSX turned into keys of JavaScript objects and the JavaScript names cannot contain dashes or reversed words, it is recommended to use camelCase wherever applicable in JSX code. The attribute `class` is a keyword in JavaScript, and JSX is an extension of JavaScript. That's the principle reason why React uses `className` instead of `class`. Pass a string as the `className` prop.
1258
1258
1259
1259
```jsx harmony
1260
1260
render() {
@@ -4957,7 +4957,7 @@ class ParentComponent extends React.Component {
4957
4957
}
4958
4958
```
4959
4959
4960
-
Because the declarative approach separates concerns, this part of it only needs to handle how the UI should look in a sepecific state, and is therefore much simpler to understand.
4960
+
Because the declarative approach separates concerns, this part of it only needs to handle how the UI should look in a specific state, and is therefore much simpler to understand.
4961
4961
4962
4962
**[⬆ Back to Top](#table-of-contents)**
4963
4963
@@ -5520,7 +5520,7 @@ class ParentComponent extends React.Component {
5520
5520
}
5521
5521
```
5522
5522
5523
-
The preceeding code updated two state variables with in an event handler. However, React will perform automatic batching feature and the component will be re-rendered only once for better performance.
5523
+
The preceding code updated two state variables with in an event handler. However, React will perform automatic batching feature and the component will be re-rendered only once for better performance.
5524
5524
5525
5525
**[⬆ Back to Top](#table-of-contents)**
5526
5526
@@ -5597,7 +5597,7 @@ class ParentComponent extends React.Component {
5597
5597
5598
5598
256. ### How do you update objects inside state?
5599
5599
5600
-
You cannot update the objects which exists in the state directly. Instead, you should create a fresh new object (or copy from the existing object) and update the latest state using the newly created object. Eventhough JavaScript objects are mutable, you need to treate objects inside state as read-only while updating the state.
5600
+
You cannot update the objects which exists in the state directly. Instead, you should create a fresh new object (or copy from the existing object) and update the latest state using the newly created object. Eventhough JavaScript objects are mutable, you need to treat objects inside state as read-only while updating the state.
5601
5601
5602
5602
Let's see this comparison with an example. The issue with regular object mutation approach can be described by updating the user details fields of `Profile` component. The properties of `Profile` component such as firstName, lastName and age details mutated in an event handler as shown below.
5603
5603
@@ -5683,7 +5683,7 @@ class ParentComponent extends React.Component {
5683
5683
user.address.country="Germany";
5684
5684
```
5685
5685
5686
-
This issue can be fixed by flattening all the fields into a top-level object or create a new object for each nested object and point it to it's parent object. In this example, first you need to create copy of address object and update it with the latest value. Later, the adress object should be linked to parent user object something like below.
5686
+
This issue can be fixed by flattening all the fields into a top-level object or create a new object for each nested object and point it to it's parent object. In this example, first you need to create copy of address object and update it with the latest value. Later, the address object should be linked to parent user object something like below.
5687
5687
5688
5688
```js
5689
5689
setUser({
@@ -5703,7 +5703,7 @@ class ParentComponent extends React.Component {
5703
5703
5704
5704
Eventhough arrays in JavaScript are mutable in nature, you need to treat them as immutable while storing them in a state. That means, similar to objects, the arrays cannot be updated directly inside state. Instead, you need to create a copy of the existing array and then set the state to use newly copied array.
5705
5705
5706
-
To ensure that arrays are not mutated, the mutation operations like direct direct assigment(arr[1]='one'), push, pop, shift, unshift, splice etc methods should be avoided on original array. Instead, you can create a copy of existing array with help of array operations such as filter, map, slice, spread syntax etc.
5706
+
To ensure that arrays are not mutated, the mutation operations like direct direct assignment(arr[1]='one'), push, pop, shift, unshift, splice etc methods should be avoided on original array. Instead, you can create a copy of existing array with help of array operations such as filter, map, slice, spread syntax etc.
5707
5707
5708
5708
For example, the below push operation doesn't add the new todo to the total todo's list in an event handler.
5709
5709
@@ -5743,7 +5743,7 @@ class ParentComponent extends React.Component {
5743
5743
2. Replace `useState` hook with `useImmer` hook by importing at the top
5744
5744
3. The setter function of `useImmer` hook can be used to update the state.
5745
5745
5746
-
For example, the mutation syntax of immer library simplies the nested address object of user state as follows,
5746
+
For example, the mutation syntax of immer library simplifies the nested address object of user state as follows,
5747
5747
5748
5748
```jsx
5749
5749
import { useImmer } from"use-immer";
@@ -5762,7 +5762,7 @@ class ParentComponent extends React.Component {
5762
5762
});
5763
5763
```
5764
5764
5765
-
The preceeding code enables you to update nested objects with a conceise mutation syntax.
5765
+
The preceding code enables you to update nested objects with a conceise mutation syntax.
Copy file name to clipboardExpand all lines: coding-exercise/README.md
+1-1
Original file line number
Diff line number
Diff line change
@@ -32,7 +32,7 @@ export default function Counter() {
32
32
<p>
33
33
34
34
##### Answer: 3
35
-
State values are fixed(i.e, default value 5) in each render and setting the state only changes it for the next render. React will wait untill all the code executed with in an event handler before your state updates follwed by re-rendering the UI. Also, all the 3 setter function calls are replacing the calculated value. Hence, irrespective of how many times you call `setCounter(counter + 5)` the final value is 10(5+5).
35
+
State values are fixed(i.e, default value 5) in each render and setting the state only changes it for the next render. React will wait until all the code executed with in an event handler before your state updates followed by re-rendering the UI. Also, all the 3 setter function calls are replacing the calculated value. Hence, irrespective of how many times you call `setCounter(counter + 5)` the final value is 10(5+5).
36
36
37
37
This can be visuallized by substituting with state variable values in the particular render,
0 commit comments