mirror of
https://github.com/reactjs/react.dev.git
synced 2026-02-24 20:53:08 +00:00
[Beta] Update Describing the UI Doc content format (#5039)
* [Beta] Update `Describing the UI` Doc content format * [Beta] Update link * [Beta] Revert
This commit is contained in:
@@ -258,7 +258,7 @@ This style works well for simple conditions, but use it in moderation. If your c
|
||||
|
||||
### Logical AND operator (`&&`) {/*logical-and-operator-*/}
|
||||
|
||||
Another common shortcut you'll encounter is the [JavaScript logical AND (`&&`) operator](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Logical_AND#:~:text=The%20logical%20AND%20(%20%26%26%20)%20operator,it%20returns%20a%20Boolean%20value.). Inside React components, it often comes up when you want to render some JSX when the condition is true, **or render nothing otherwise.** With `&&`, you could conditionally render the checkmark only if `isPacked` is `true`:
|
||||
Another common shortcut you'll encounter is the [JavaScript logical AND (`&&`) operator.](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Logical_AND#:~:text=The%20logical%20AND%20(%20%26%26%20)%20operator,it%20returns%20a%20Boolean%20value.) Inside React components, it often comes up when you want to render some JSX when the condition is true, **or render nothing otherwise.** With `&&`, you could conditionally render the checkmark only if `isPacked` is `true`:
|
||||
|
||||
```js
|
||||
return (
|
||||
|
||||
@@ -116,7 +116,7 @@ export default function TodoList() {
|
||||
You can only use curly braces in two ways inside JSX:
|
||||
|
||||
1. **As text** directly inside a JSX tag: `<h1>{name}'s To Do List</h1>` works, but `<{tag}>Gregorio Y. Zara's To Do List</{tag}>` will not.
|
||||
2. **As attributes** immediately following the `=` sign: `src={avatar}` will read the `avatar` variable, but `src="{avatar}"` will pass the string `{avatar}`.
|
||||
2. **As attributes** immediately following the `=` sign: `src={avatar}` will read the `avatar` variable, but `src="{avatar}"` will pass the string `"{avatar}"`.
|
||||
|
||||
## Using "double curlies": CSS and other objects in JSX {/*using-double-curlies-css-and-other-objects-in-jsx*/}
|
||||
|
||||
@@ -426,7 +426,7 @@ body > div > div { padding: 20px; }
|
||||
|
||||
#### Write an expression inside JSX curly braces {/*write-an-expression-inside-jsx-curly-braces*/}
|
||||
|
||||
In the object below, the full image URL is split into four parts: base URL, `imageId`, `imageSize`, and file extension.
|
||||
In the object below, the full image URL is split into four parts: base URL, `imageId`, `imageSize`, and file extension.
|
||||
|
||||
We want the image URL to combine these attributes together: base URL (always `'https://i.imgur.com/'`), `imageId` (`'7vQD0fP'`), `imageSize` (`'s'`), and file extension (always `'.jpg'`). However, something is wrong with how the `<img>` tag specifies its `src`.
|
||||
|
||||
|
||||
@@ -43,7 +43,7 @@ function double(number) {
|
||||
}
|
||||
```
|
||||
|
||||
In the above example, `double()` is a **pure function.** If you pass it `3`, it will return `6`. Always.
|
||||
In the above example, `double` is a **pure function.** If you pass it `3`, it will return `6`. Always.
|
||||
|
||||
React is designed around this concept. **React assumes that every component you write is a pure function.** This means that React components you write must always return the same JSX given the same inputs:
|
||||
|
||||
@@ -215,7 +215,7 @@ Every new React feature we're building takes advantage of purity. From data fetc
|
||||
* **It minds its own business.** It should not change any objects or variables that existed before rendering.
|
||||
* **Same inputs, same output.** Given the same inputs, a component should always return the same JSX.
|
||||
* Rendering can happen at any time, so components should not depend on each others' rendering sequence.
|
||||
* 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](reacting-to-input-with-state) instead of mutating preexisting objects.
|
||||
* 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.
|
||||
* 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`.
|
||||
* Writing pure functions takes a bit of practice, but it unlocks the power of React's paradigm.
|
||||
|
||||
|
||||
@@ -169,7 +169,7 @@ If you don't want to add an extra `<div>` to your markup, you can write `<>` and
|
||||
</>
|
||||
```
|
||||
|
||||
This empty tag is called a *[React fragment](/apis/react/Fragment)*. React fragments let you group things without leaving any trace in the browser HTML tree.
|
||||
This empty tag is called a *[React fragment.](/apis/react/Fragment)* React fragments let you group things without leaving any trace in the browser HTML tree.
|
||||
|
||||
<DeepDive title="Why do multiple JSX tags need to be wrapped?">
|
||||
|
||||
|
||||
Reference in New Issue
Block a user