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: src/content/learn/conditional-rendering.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -256,7 +256,7 @@ export default function PackingList() {
256
256
257
257
</Sandpack>
258
258
259
-
This style works well for simple conditions, but use it inmoderation. If your components get messy with too much nested conditional markup, consider extracting child components to clean things up. In React, markup is a part of your code, so you can use tools like variables and functions to tidy up complex expressions.
259
+
This style works well for simple conditions, but use it inmoderation. If your Components get messy with too much nested conditional markup, consider extracting child components to clean things up. In React, markup is a part of your code, so you can use tools like variables and functions to tidy up complex expressions.
Copy file name to clipboardExpand all lines: src/content/learn/keeping-components-pure.md
+5-5Lines changed: 5 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,15 +4,15 @@ title: Keeping Components Pure
4
4
5
5
<Intro>
6
6
7
-
Some JavaScript functions are *pure.* Pure functions only perform a calculation and nothing more. By strictly only writing your components as pure functions, you can avoid an entire class of baffling bugs and unpredictable behavior as your codebase grows. To get these benefits, though, there are a few rules you must follow.
7
+
Some JavaScript functions are *pure.* Pure functions only perform a calculation and nothing more. By strictly only writing your Components as pure functions, you can avoid an entire class of baffling bugs and unpredictable behavior as your codebase grows. To get these benefits, though, there are a few rules you must follow.
8
8
9
9
</Intro>
10
10
11
11
<YouWillLearn>
12
12
13
13
* What purity is and how it helps you avoid bugs
14
14
* How to keep components pure by keeping changes out of the render phase
15
-
* How to use Strict Mode to find mistakes in your components
15
+
* How to use Strict Mode to find mistakes in your Components
16
16
17
17
</YouWillLearn>
18
18
@@ -81,7 +81,7 @@ If you pass `drinkers={4}`, it will return JSX containing `4 cups of water`. Alw
81
81
82
82
Just like a math formula.
83
83
84
-
You could think of your components as recipes: if you follow them and don't introduce new ingredients during the cooking process, you will get the same dish every time. That "dish" is the JSX that the component serves to React to [render.](/learn/render-and-commit)
84
+
You could think of your Components as recipes: if you follow them and don't introduce new ingredients during the cooking process, you will get the same dish every time. That "dish" is the JSX that the component serves to React to [render.](/learn/render-and-commit)
85
85
86
86
<Illustrationsrc="/images/docs/illustrations/i_puritea-recipe.png"alt="A tea recipe for x people: take x cups of water, add x spoons of tea and 0.5x spoons of spices, and 0.5x cups of milk" />
87
87
@@ -143,7 +143,7 @@ export default function TeaSet() {
143
143
144
144
Now your component is pure, as the JSX it returns only depends on the `guest` prop.
145
145
146
-
In general, you should not expect your components to be rendered in any particular order. It doesn't matter if you call <Math><MathI>y</MathI> = 2<MathI>x</MathI></Math> before or after <Math><MathI>y</MathI> = 5<MathI>x</MathI></Math>: both formulas will resolve independently of each other. In the same way, each component should only "think for itself", and not attempt to coordinate with or depend upon others during rendering. Rendering is like a school exam: each component should calculate JSX on their own!
146
+
In general, you should not expect your Components to be rendered in any particular order. It doesn't matter if you call <Math><MathI>y</MathI> = 2<MathI>x</MathI></Math> before or after <Math><MathI>y</MathI> = 5<MathI>x</MathI></Math>: both formulas will resolve independently of each other. In the same way, each component should only "think for itself", and not attempt to coordinate with or depend upon others during rendering. Rendering is like a school exam: each component should calculate JSX on their own!
147
147
148
148
<DeepDive>
149
149
@@ -219,7 +219,7 @@ Every new React feature we're building takes advantage of purity. From data fetc
219
219
***It minds its own business.** It should not change any objects or variables that existed before rendering.
220
220
***Same inputs, same output.** Given the same inputs, a component should always return the same JSX.
221
221
* Rendering can happen at any time, so components should not depend on each others' rendering sequence.
222
-
* You should not mutate any of the inputs that your components use for rendering. That includes props, state, and context. To update the screen, ["set" state](/learn/state-a-components-memory) instead of mutating preexisting objects.
222
+
* You should not mutate any of the inputs that your Components use for rendering. That includes props, state, and context. To update the screen, ["set" state](/learn/state-a-components-memory) instead of mutating preexisting objects.
223
223
* Strive to express your component's logic in the JSX you return. When you need to "change things", you'll usually want to do it in an event handler. As a last resort, you can `useEffect`.
224
224
* Writing pure functions takes a bit of practice, but it unlocks the power of React's paradigm.
0 commit comments