跳转到主要内容

React

import { PagesBuildPreset, Render, PackageManagers, DashButton } from "~/components";

In this guide, you will create a new React application and deploy it using Cloudflare Pages.

Setting up a new project

Use the create-cloudflare CLI (C3) to set up a new project. C3 will create a new project directory, initiate React's official setup tool, and provide the option to deploy instantly.

To use create-cloudflare to create a new React project, run the following command:

create-cloudflare will install dependencies, including the Wrangler CLI and the Cloudflare Pages adapter, and ask you setup questions.

Go to the application's directory:

cd my-react-app

From here you can run your application with:

npm run dev

Deploy with Cloudflare Pages

<Render file="deploy-via-c3" product="pages" params={{ name: "React" }} />

Deploy via the Cloudflare dashboard

  1. In the Cloudflare dashboard, go to the Workers & Pages page.

  2. Select Create application > Pages > Import an existing Git repository.

  3. Select the new GitHub repository that you created and, in the Set up builds and deployments section, provide the following information:

After configuring your site, you can begin your first deploy. You should see Cloudflare Pages installing react, your project dependencies, and building your site, before deploying it.

:::note

For the complete guide to deploying your first site to Cloudflare Pages, refer to the Get started guide.

:::

After deploying your site, you will receive a unique subdomain for your project on *.pages.dev. Every time you commit new code to your React application, Cloudflare Pages will automatically rebuild your project and deploy it. You will also get access to preview deployments on new pull requests, so you can preview how changes look to your site before deploying them to production.

:::note[SPA rendering]

By default, Cloudflare Pages assumes you are developing a single-page application. Refer to Serving Pages for more information.

:::

<Render file="framework-guides/learn-more" product="pages" params={{ one: "React" }} />