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
If your app has constraints not well-served by existing frameworks, you prefer to build your own framework, or you just want to learn the basics of a React app, you can [build a React app from scratch](/learn/build-a-react-app-from-scratch).
#### Full-stack frameworks do not require a server. {/*react-frameworks-do-not-require-a-server*/}
29
20
30
21
All the frameworks on this page support client-side rendering ([CSR](https://developer.mozilla.org/en-US/docs/Glossary/CSR)), single-page apps ([SPA](https://developer.mozilla.org/en-US/docs/Glossary/SPA)), and static-site generation ([SSG](https://developer.mozilla.org/en-US/docs/Glossary/SSG)). These apps can be deployed to a [CDN](https://developer.mozilla.org/en-US/docs/Glossary/CDN) or static hosting service without a server. Additionally, these frameworks allow you to add server-side rendering on a per-route basis, when it makes sense for your use case.
31
22
32
23
This allows you to start with a client-only app, and if your needs change later, you can opt-in to using server features on individual routes without rewriting your app. See your framework's documentation for configuring the rendering strategy.
33
-
>>>>>>> c03f0290502e0b1210f50faaa464489accd57c35
34
24
35
25
</Note>
36
26
@@ -69,11 +59,7 @@ npx create-expo-app@latest
69
59
Expo 由 [Expo 公司](https://expo.dev/about) 维护。使用 Expo 构建应用是免费的,你可以将应用提交到 Google 和 Apple 应用商店,没有任何限制。Expo 还提供可选的付费云服务。
If your app has constraints not well-served by existing frameworks, you prefer to build your own framework, or you just want to learn the basics of a React app, there are other options available for starting a React project from scratch.
120
106
121
-
<<<<<<< HEAD
122
-
#### 你推荐使用 Vite 吗? {/*do-you-recommend-vite*/}
123
-
124
-
我们推荐了一些基于 Vite 的选择。
125
-
126
-
React Router v7 是一个基于 Vite 的框架,允许你使用 Vite 的快速开发服务器和构建工具,同时提供路由和数据获取功能。与其他推荐的框架一样,你可以用 React Router v7 构建单页应用。
Starting from scratch gives you more flexibility, but does require that you make choices on which tools to use for routing, data fetching, and other common usage patterns. It's a lot like building your own framework, instead of using a framework that already exists. The [frameworks we recommend](#recommended-react-frameworks) have built-in solutions for these problems.
135
108
136
109
If you want to build your own solutions, see our guide to [build a React app from Scratch](/learn/build-a-react-app-from-scratch) for instructions on how to set up a new React project starting with a built tool like [Vite](https://vite.dev/), [Parcel](https://parceljs.org/), or [RSbuild](https://rsbuild.dev/).
If a framework is not a good fit for your project, you prefer to build your own framework, or you just want to learn the basics of a React app you can [build a React app from scratch](/learn/build-a-react-app-from-scratch).
<Illustrationcaption="State update..."alt="React as a server in a restaurant, serving a Card UI to the user, represented as a patron with a cursor for their head. The patron expresses they want a pink card, not a black one!"src="/images/docs/illustrations/i_rerender1.png" />
85
-
<Illustrationcaption="...triggers..."alt="React returns to the Component Kitchen and tells the Card Chef they need a pink Card."src="/images/docs/illustrations/i_rerender2.png" />
86
-
<Illustrationcaption="...render!"alt="The Card Chef gives React the pink Card."src="/images/docs/illustrations/i_rerender3.png" />
## 步骤 3: React 把更改提交到 DOM 上 {/*step-3-react-commits-changes-to-the-dom*/}
166
156
167
-
<<<<<<< HEAD
168
157
在渲染(调用)你的组件之后,React 将会修改 DOM。
169
158
170
-
***对于初次渲染,** React 会使用 [`appendChild()`](https://developer.mozilla.org/docs/Web/API/Node/appendChild) DOM API 将其创建的所有 DOM 节点放在屏幕上。
171
-
***对于重渲染,** React 将应用最少的必要操作(在渲染时计算!),以使得 DOM 与最新的渲染输出相互匹配。
172
-
=======
173
-
After rendering (calling) your components, React will modify the DOM.
174
-
175
-
***For the initial render,** React will use the [`appendChild()`](https://developer.mozilla.org/docs/Web/API/Node/appendChild) DOM API to put all the DOM nodes it has created on screen.
176
-
***For re-renders,** React will apply the minimal necessary operations (calculated while rendering!) to make the DOM match the latest rendering output.
177
-
>>>>>>> c03f0290502e0b1210f50faaa464489accd57c35
159
+
***对于初次渲染**,React 会使用 [`appendChild()`](https://developer.mozilla.org/docs/Web/API/Node/appendChild) DOM API 将其创建的所有 DOM 节点放在屏幕上。
160
+
***对于重渲染**,React 将应用最少的必要操作(在渲染时计算!),以使得 DOM 与最新的渲染输出相互匹配。
178
161
179
162
**React 仅在渲染之间存在差异时才会更改 DOM 节点。** 例如,有一个组件,它每秒使用从父组件传递下来的不同属性重新渲染一次。注意,你可以添加一些文本到 `<input>` 标签,更新它的 `value`,但是文本不会在组件重渲染时消失:
Copy file name to clipboardExpand all lines: src/content/learn/state-a-components-memory.md
+1-6
Original file line number
Diff line number
Diff line change
@@ -1457,12 +1457,7 @@ export default function FeedbackForm() {
1457
1457
1458
1458
#### 移除不必要的 state {/*remove-unnecessary-state*/}
1459
1459
1460
-
<<<<<<< HEAD
1461
-
当按钮被点击时,这个例子应该询问用户的名字,然后显示一个 alert 欢迎他们。你尝试使用 state 来保存名字,但由于某种原因,它始终显示“Hello, !”。
1462
-
=======
1463
-
When the button is clicked, this example should ask for the user's name and then display an alert greeting them. You tried to use state to keep the name, but for some reason the first time it shows "Hello, !", and then "Hello, [name]!" with the previous input every time after.
1464
-
>>>>>>> c03f0290502e0b1210f50faaa464489accd57c35
1465
-
1460
+
当按钮被点击时,这个例子应该询问用户的名字,然后显示一个 alert 欢迎他们。你尝试使用 state 来保存名字,但由于某种原因,它显示“Hello, !”,然后是“Hello, [name]!”,每次之后都使用以前的输入。
1466
1461
1467
1462
要修复此代码,请删除不必要的 state 变量。(我们将在稍后讨论[为什么上述代码不起作用](/learn/state-as-a-snapshot)。)
When you mark a square with an `X` or an `O` you aren't first checking to see if the square already has an `X` or `O` value. You can fix this by *returning early*. You'll check to see if the square already has an `X` or an `O`. If the square is already filled, you will `return` in the `handleClick` function early--before it tries to update the board state.
1421
-
>>>>>>> c03f0290502e0b1210f50faaa464489accd57c35
1422
1410
1423
1411
```js {2,3,4}
1424
1412
functionhandleClick(i) {
@@ -1568,11 +1556,7 @@ function calculateWinner(squares) {
You will call `calculateWinner(squares)` in the `Board` component's `handleClick` function to check if a player has won. You can perform this check at the same time you check if a user has clicked a square that already has an `X` or an `O`. We'd like to return early in both cases:
By default, a `<button>` inside a `<form>` without a `type` attribute will submit it. This can be surprising! If you have your own custom `Button` React component, consider using [`<button type="button">`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/button) instead of `<button>` (with no type). Then, to be explicit, use `<button type="submit">` for buttons that *are* supposed to submit the form.
- Data fetching with Suspense-enabled frameworks like [Relay](https://relay.dev/docs/guided-tour/rendering/loading-states/) and [Next.js](https://nextjs.org/docs/app/getting-started/fetching-data#with-suspense)
97
-
- Lazy-loading component code with [`lazy`](/reference/react/lazy)
98
-
- Reading the value of a Promise with [`use`](/reference/react/use)
0 commit comments