Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(docs): translate start a new react project #379

Merged
merged 2 commits into from
Apr 28, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 35 additions & 35 deletions src/content/learn/start-a-new-react-project.md
Original file line number Diff line number Diff line change
@@ -1,110 +1,110 @@
---
title: Start a New React Project
title: 開始一個新的 React 專案
---

<Intro>

If you want to build a new app or a new website fully with React, we recommend picking one of the React-powered frameworks popular in the community. Frameworks provide features that most apps and sites eventually need, including routing, data fetching, and generating HTML.
如果你想要完全使用 React 建立新的應用程式或網站,我們建議從社群中流行的 React 框架中選擇一個。框架提供大多數應用程式和網站最終需要的功能,包括路由(routing)、資料擷取(data fetching)和產生 HTML

</Intro>

<Note>

**You need to install [Node.js](https://nodejs.org/en/) for local development.** You can *also* choose to use Node.js in production, but you don't have to. Many React frameworks support export to a static HTML/CSS/JS folder.
**你需要在你的本機開發環境安裝 [Node.js](https://nodejs.org/en/)** 你*也*可以選擇使用 Node.js production 環境,但你不需要這麼做。許多 React 框架支援導出靜態的 HTML/CSS/JS 文件。
neighborhood999 marked this conversation as resolved.
Show resolved Hide resolved

</Note>

## Production-grade React frameworks {/*production-grade-react-frameworks*/}
## 生產級別的 React 框架 {/*production-grade-react-frameworks*/}

### Next.js {/*nextjs*/}

**[Next.js](https://nextjs.org/) is a full-stack React framework.** It's versatile and lets you create React apps of any size--from a mostly static blog to a complex dynamic application. To create a new Next.js project, run in your terminal:
**[Next.js](https://nextjs.org/) 是一個全端 React 框架。** 它非常靈活,讓你可以建立任何大小的 React 應用程式 - 從大部分是靜態的部落格到複雜動態的應用程式。要建立新的 Next.js 專案,在你的終端機中執行以下命令:

<TerminalBlock>
npx create-next-app
</TerminalBlock>

If you're new to Next.js, check out the [Next.js tutorial.](https://nextjs.org/learn/foundations/about-nextjs)
如果你是第一次使用 Next.js,請參考 [Next.js 教學](https://nextjs.org/learn/foundations/about-nextjs)

Next.js is maintained by [Vercel](https://vercel.com/). You can [deploy a Next.js app](https://nextjs.org/docs/deployment) to any Node.js or serverless hosting, or to your own server. [Fully static Next.js apps](https://nextjs.org/docs/advanced-features/static-html-export) can be deployed to any static hosting.
Next.js 是由 [Vercel](https://vercel.com/) 維護。你可以將 [Next.js 應用程式部署](https://nextjs.org/docs/deployment)到任何 Node.js serverless 主機,或是你自己的伺服器上。[完全靜態的 Next.js 應用程式](https://nextjs.org/docs/advanced-features/static-html-export) 可以部署到任何靜態主機上。

### Remix {/*remix*/}

**[Remix](https://remix.run/) is a full-stack React framework with nested routing.** It lets you break your app into nested parts that can load data in parallel and refresh in response to the user actions. To create a new Remix project, run:
**[Remix](https://remix.run/) 是一個具有巢狀路由(nested route)的全端 React 框架。** 它讓你將應用程序分成可以並行載入資料並根據使用者的操作刷新。要建立新的 Remix 專案,執行:
neighborhood999 marked this conversation as resolved.
Show resolved Hide resolved

<TerminalBlock>
npx create-remix
</TerminalBlock>

If you're new to Remix, check out the Remix [blog tutorial](https://remix.run/docs/en/main/tutorials/blog) (short) and [app tutorial](https://remix.run/docs/en/main/tutorials/jokes) (long).
如果你是第一次使用 Remix,請參考 Remix [部落格教學](https://remix.run/docs/en/main/tutorials/blog)(短篇)以及[應用程式教學](https://remix.run/docs/en/main/tutorials/jokes)(長篇)。

Remix is maintained by [Shopify](https://www.shopify.com/). When you create a Remix project, you need to [pick your deployment target](https://remix.run/docs/en/main/guides/deployment). You can deploy a Remix app to any Node.js or serverless hosting by using or writing an [adapter](https://remix.run/docs/en/main/other-api/adapter).
Remix 是由 [Shopify](https://www.shopify.com/) 維護。當你建立 Remix 專案時,需要[選擇部署目標](https://remix.run/docs/en/main/guides/deployment)。你可以使用或撰寫一個 [adapter](https://remix.run/docs/en/main/other-api/adapter),將 Remix 應用程式部署到任何 Node.js 或 serverless 主機上。

### Gatsby {/*gatsby*/}

**[Gatsby](https://www.gatsbyjs.com/) is a React framework for fast CMS-backed websites.** Its rich plugin ecosystem and its GraphQL data layer simplify integrating content, APIs, and services into one website. To create a new Gatsby project, run:
**[Gatsby](https://www.gatsbyjs.com/) 是一個用於快速 CMS 支援網站的 React 框架。** 它豐富的外掛生態系統和 GraphQL 資料層,簡化了將內容、API 和服務整合到一個網站中。要建立新的 Gatsby 專案,請執行以下命令:
neighborhood999 marked this conversation as resolved.
Show resolved Hide resolved

<TerminalBlock>
npx create-gatsby
</TerminalBlock>

If you're new to Gatsby, check out the [Gatsby tutorial.](https://www.gatsbyjs.com/docs/tutorial/)
如果你是第一次使用 Gatsby,請參考 [Gatsby 教學](https://www.gatsbyjs.com/docs/tutorial/)

Gatsby is maintained by [Netlify](https://www.netlify.com/). You can [deploy a fully static Gatsby site](https://www.gatsbyjs.com/docs/how-to/previews-deploys-hosting) to any static hosting. If you opt into using server-only features, make sure your hosting provider supports them for Gatsby.
Gatsby [Netlify](https://www.netlify.com/) 維護。你可以將完全靜態的 [Gatsby 網站部署]((https://www.gatsbyjs.com/docs/how-to/previews-deploys-hosting))到任何靜態主機上。如果你選擇使用 server-only 的功能,請確保你的主機提供商支援它們用於 Gatsby
neighborhood999 marked this conversation as resolved.
Show resolved Hide resolved

### Expo (for native apps) {/*expo*/}
### Expo(針對 native apps {/*expo*/}

**[Expo](https://expo.dev/) is a React framework that lets you create universal Android, iOS, and web apps with truly native UIs.** It provides an SDK for [React Native](https://reactnative.dev/) that makes the native parts easier to use. To create a new Expo project, run:
**[Expo](https://expo.dev/) 是一個 React 框架,讓你可以在 AndroidiOS 和 Web 應用程式建立通用的 native UI。** 它提供了一個 [React Native](https://reactnative.dev/) 的 SDK,使原生部分更容易使用。要建立新的 Expo 專案,請執行:
neighborhood999 marked this conversation as resolved.
Show resolved Hide resolved

<TerminalBlock>
npx create-expo-app
</TerminalBlock>

If you're new to Expo, check out the [Expo tutorial](https://docs.expo.dev/tutorial/introduction/).
如果你是你一次使用 Expo,請參考 [Expo 教學](https://docs.expo.dev/tutorial/introduction/)
neighborhood999 marked this conversation as resolved.
Show resolved Hide resolved

Expo is maintained by [Expo (the company)](https://expo.dev/about). Building apps with Expo is free, and you can submit them to the Google and Apple app stores without restrictions. Expo additionally provides opt-in paid cloud services.
Expo [Expo(公司)](https://expo.dev/about)維護。使用 Expo 構建應用程式是免費的,你可以無限制地將它們提交到 Google Apple 應用商店。另外,Expo 還提供可選的付費雲服務。

<DeepDive>

#### Can I use React without a framework? {/*can-i-use-react-without-a-framework*/}
#### 我可以不使用框架來使用 React 嗎? {/*can-i-use-react-without-a-framework*/}
neighborhood999 marked this conversation as resolved.
Show resolved Hide resolved

You can definitely use React without a framework--that's how you'd [use React for a part of your page.](/learn/add-react-to-an-existing-project#using-react-for-a-part-of-your-existing-page) **However, if you're building a new app or a site fully with React, we recommend using a framework.**
你絕對可以在沒有框架的情況下使用 React--這是你如何[在頁面的一部分中使用 React](/learn/add-react-to-an-existing-project#using-react-for-a-part-of-your-existing-page) **然而,如果你正在完全使用 React 建立新應用程式或網站,我們建議你使用框架。**
neighborhood999 marked this conversation as resolved.
Show resolved Hide resolved

Here's why.
這是為什麼。
neighborhood999 marked this conversation as resolved.
Show resolved Hide resolved

Even if you don't need routing or data fetching at first, you'll likely want to add some libraries for them. As your JavaScript bundle grows with every new feature, you might have to figure out how to split code for every route individually. As your data fetching needs get more complex, you are likely to encounter server-client network waterfalls that make your app feel very slow. As your audience includes more users with poor network conditions and low-end devices, you might need to generate HTML from your components to display content early--either on the server, or during the build time. Changing your setup to run some of your code on the server or during the build can be very tricky.
即使一開始不需要 routing 或是 data fetching,你可能還是想要增加一些相關的函式庫。隨著每個新功能的加入,JavaScript bundle 會越來越大,你可能需要找出如何為每個 routing 單獨拆分程式碼。當 data fetching 需求變得更加複雜時,你可能會遇到 server-clent 的網路 waterfall 現象,這會使你的應用程式感覺非常緩慢。當你的使用者中包含了有低速網路和廉價設備的受眾時,你可能需要從 component 產成 HTML 以提早顯示內容 - 在伺服器上或在建置期間執行此操作。更改設定以在伺服器上或在建置期間執行部分程式碼可能非常棘手。
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
即使一開始不需要 routing 或是 data fetching,你可能還是想要增加一些相關的函式庫。隨著每個新功能的加入,JavaScript bundle 會越來越大,你可能需要找出如何為每個 routing 單獨拆分程式碼。當 data fetching 需求變得更加複雜時,你可能會遇到 server-clent 的網路 waterfall 現象,這會使你的應用程式感覺非常緩慢。當你的使用者中包含了有低速網路和廉價設備的受眾時,你可能需要從 component 產成 HTML 以提早顯示內容 - 在伺服器上或在建置期間執行此操作。更改設定以在伺服器上或在建置期間執行部分程式碼可能非常棘手。
即使在一開始可能不需要 routing 或是 data fetching,你可能還是想要增加一些相關的函式庫。隨著每個新功能的加入,JavaScript bundle 會越來越大,你可能需要找出如何為每個 routing 單獨拆分程式碼。當 data fetching 需求變得更加複雜時,你可能會遇到 server-client 的 network waterfalls,這會使你的應用程式感覺非常緩慢。當你的使用者中包含了低速網路和低階設備的受眾時,你可能需要從元件產出 HTML 以提早顯示內容 - 無論是在伺服器上或在建置期間。更改設定以在伺服器上或在建置期間執行部分程式碼可能非常棘手。

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I kept component here instead of translating it to 元件.


**These problems are not React-specific. This is why Svelte has SvelteKit, Vue has Nuxt, and so on.** To solve these problems on your own, you'll need to integrate your bundler with your router and with your data fetching library. It's not hard to get an initial setup working, but there are a lot of subtleties involved in making an app that loads quickly even as it grows over time. You'll want to send down the minimal amount of app code but do so in a single clientserver roundtrip, in parallel with any data required for the page. You'll likely want the page to be interactive before your JavaScript code even runs, to support progressive enhancement. You may want to generate a folder of fully static HTML files for your marketing pages that can be hosted anywhere and still work with JavaScript disabled. Building these capabilities yourself takes real work.
**這些問題並非 React 特有的。這就是為什麼 Svelte SvelteKitVue Nuxt 等等。** 要自己解決這些問題,你需要將 bundle 工具與 routing 和 data fetching 函式庫整合在一起。一開始設定不難,但隨著時間的推移,製作能夠快速載入應用程式所涉及的微妙之處很多。你希望以最少量的應用程式程式碼發送它,在單個 client-server 回合中完成,與頁面所需的任何資料並行。你可能希望在 JavaScript 程式碼執行之前就可與頁互動面,以支援漸進式增強(progressive enhancement)功能。你可能還想產生完全靜態的 HTML 文件來顯示行銷網頁,在禁用 JavaScript 時也可以在任何地方托管且正常運作。建立這些功能需要真正付出努力。
neighborhood999 marked this conversation as resolved.
Show resolved Hide resolved

**React frameworks on this page solve problems like these by default, with no extra work from your side.** They let you start very lean and then scale your app with your needs. Each React framework has a community, so finding answers to questions and upgrading tooling is easier. Frameworks also give structure to your code, helping you and others retain context and skills between different projects. Conversely, with a custom setup it's easier to get stuck on unsupported dependency versions, and you'll essentially end up creating your own framework—albeit one with no community or upgrade path (and if it's anything like the ones we've made in the past, more haphazardly designed).
**這個頁面上的 React 框架可以自動解決這些問題,而不需要你做任何額外的工作。** 它們讓你可以從非常簡單的開始,然後根據你的需求擴展應用程式。每個 React 框架都有一個社群,因此更容易找到答案和升級工具。框架還可以給你的程式碼提供結構,幫助你和其他人在不同項目之間保持 context 和技能。相反地,使用客製化設定會更容易陷入不支援依賴版本中,最終你將建立自己的框架 - 雖然沒有社區或升級路徑(如果像我們過去製作過的那些一樣混亂設計)。
neighborhood999 marked this conversation as resolved.
Show resolved Hide resolved

If you're still not convinced, or your app has unusual constraints not served well by these frameworks and you'd like to roll your own custom setup, we can't stop you--go for it! Grab `react` and `react-dom` from npm, set up your custom build process with a bundler like [Vite](https://vitejs.dev/) or [Parcel](https://parceljs.org/), and add other tools as you need them for routing, static generation or server-side rendering, and more.
如果你仍然不信服,或者你的應用程式有這些框架無法很好地滿足的非常規限制,並且你想要自己克制設定,我們不能阻止你 - 去做吧!從 npm 中獲取 `react` `react-dom`,使用像 [Vite](https://vitejs.dev/) [Parcel](https://parceljs.org/) 這樣的 bundle 工具設定自己的客製構建過程,並根據需求新增其他工具以進行 routingstatic generation server-side rendering 等操作。
neighborhood999 marked this conversation as resolved.
Show resolved Hide resolved
</DeepDive>

## Bleeding-edge React frameworks {/*bleeding-edge-react-frameworks*/}
## 前沿的 React 框架 {/*bleeding-edge-react-frameworks*/}

As we've explored how to continue improving React, we realized that integrating React more closely with frameworks (specifically, with routing, bundling, and server technologies) is our biggest opportunity to help React users build better apps. The Next.js team has agreed to collaborate with us in researching, developing, integrating, and testing framework-agnostic bleeding-edge React features like [React Server Components.](/blog/2023/03/22/react-labs-what-we-have-been-working-on-march-2023#react-server-components)
當我們探索如何繼續改進 React 時,我們意識到更緊密地將 React 與框架(特別是 routingbundling 和伺服器技術)整合起來,是幫助 React 使用者構建更好應用程式的最大機會。Next.js 團隊已同意與我們合作,在研究、開發、整合和測試像是 [React Server Components](/blog/2023/03/22/react-labs-what-we-have-been-working-on-march-2023#react-server-components) 這樣不依賴於特定框架(framework-agnostic)的前沿 React 功能方面進行協作。
neighborhood999 marked this conversation as resolved.
Show resolved Hide resolved

These features are getting closer to being production-ready every day, and we've been in talks with other bundler and framework developers about integrating them. Our hope is that in a year or two, all frameworks listed on this page will have full support for these features. (If you're a framework author interested in partnering with us to experiment with these features, please let us know!)
這些功能每天都越來越接近 production-ready,我們已與其他 bundler 和框架開發人員進行了交談,以整合它們。我們的希望是,在一年或兩年內,此頁面上列出的所有框架都將完全支持這些功能。(如果你是一位框架作者,有興趣與我們合作實驗這些功能,請告訴我們!)

### Next.js (App Router) {/*nextjs-app-router*/}

**[Next.js's App Router](https://beta.nextjs.org/docs/getting-started) is a redesign of the Next.js APIs aiming to fulfill the React team’s full-stack architecture vision.** It lets you fetch data in asynchronous components that run on the server or even during the build.
**[Next.jsApp Router](https://beta.nextjs.org/docs/getting-started) Next.js API 的重新設計,旨在實現 React 團隊的全端架構願景。** 它允許你在執行於伺服器上或甚至是構建期間的非同步(asynchronous) component 中取得資料。

Next.js is maintained by [Vercel](https://vercel.com/). You can [deploy a Next.js app](https://nextjs.org/docs/deployment) to any Node.js or serverless hosting, or to your own server. Next.js also supports [static export](https://beta.nextjs.org/docs/configuring/static-export) which doesn't require a server.
Next.js [Vercel](https://vercel.com/) 維護。你可以將 Next.js 應用程式部署到任何 Node.js serverless 主機,或是你自己的伺服器上。Next.js 還支援[靜態匯出](https://beta.nextjs.org/docs/configuring/static-export),不需要伺服器即可執行。
<Pitfall>

Next.js's App Router is **currently in beta and is not yet recommended for production** (as of Mar 2023). To experiment with it in an existing Next.js project, [follow this incremental migration guide](https://beta.nextjs.org/docs/upgrade-guide#migrating-from-pages-to-app).
Next.jsApp Router 目前仍在測試(beta)階段,尚未建議用於 production 環境(截至 2023 年 3 月)。如果想要在現有的 Next.js 專案中嘗試使用它,[請參考這個漸進式遷移指南](https://beta.nextjs.org/docs/upgrade-guide#migrating-from-pages-to-app)

</Pitfall>

<DeepDive>

#### Which features make up the React team’s full-stack architecture vision? {/*which-features-make-up-the-react-teams-full-stack-architecture-vision*/}
#### React 團隊的全端架構願景包含哪些特點? {/*which-features-make-up-the-react-teams-full-stack-architecture-vision*/}

Next.js's App Router bundler fully implements the official [React Server Components specification](https://github.com/reactjs/rfcs/blob/main/text/0188-server-components.md). This lets you mix build-time, server-only, and interactive components in a single React tree.
Next.jsApp Router bundler 完全實作了官方的 [React Server Components 規範](https://github.com/reactjs/rfcs/blob/main/text/0188-server-components.md)。這讓你可以在單個 React tree 中混合 build-timeserver-only 和和互動式元件。

For example, you can write a server-only React component as an `async` function that reads from a database or from a file. Then you can pass data down from it to your interactive components:
例如,你可以將一個 server-only React component 撰寫為 `async` 函式,該函式從資料庫或文件中讀取資料。然後,你可以將資料從該 component 傳遞給互動式 component:

```js
// This component runs *only* on the server (or during the build).
Expand All @@ -120,14 +120,14 @@ async function Talks({ confId }) {
}
```

Next.js's App Router also integrates [data fetching with Suspense](/blog/2022/03/29/react-v18#suspense-in-data-frameworks). This lets you specify a loading state (like a skeleton placeholder) for different parts of your user interface directly in your React tree:
Next.jsApp Router 也整合了[使用 Suspense 進行 data fetching](/blog/2022/03/29/react-v18#suspense-in-data-frameworks)。這讓你可以直接在 React tree 中為使用者介面不同部分指定載入狀態(例如:skeleton placeholder):

```js
<Suspense fallback={<TalksLoading />}>
<Talks confId={conf.id} />
</Suspense>
```

Server Components and Suspense are React features rather than Next.js features. However, adopting them at the framework level requires buy-in and non-trivial implementation work. At the moment, the Next.js App Router is the most complete implementation. The React team is working with bundler developers to make these features easier to implement in the next generation of frameworks.
Server Component 和 Suspense React 的功能,而不是 Next.js 的。然而,在框架層面採用它們需要計畫和以及複雜的實現工作。目前,Next.js APP Router 是最完整的實現方式。React 團隊正在與 bundler開發人員合作,使這些功能在下一代框架中更容易實現。
neighborhood999 marked this conversation as resolved.
Show resolved Hide resolved

</DeepDive>