|
1 | 1 | ---
|
2 |
| -title: Start a New React Project 🚧 |
| 2 | +title: Start a New React Project |
3 | 3 | ---
|
4 | 4 |
|
5 | 5 | ## Overview
|
6 | 6 |
|
7 | 7 | <p class="intro" markdown>
|
8 | 8 |
|
9 |
| -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. |
| 9 | +If you want to build a new app or a new website fully with ReactPy, we recommend picking one of the ReactPy-compatible backends popular in the community. These backend frameworks provide features that most apps and sites eventually need, including routing, data fetching, and session management. |
10 | 10 |
|
11 | 11 | </p>
|
12 | 12 |
|
13 |
| -<Note> |
14 | 13 |
|
15 |
| -**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. |
| 14 | +## Built-in Backends |
16 | 15 |
|
17 |
| -</Note> |
| 16 | +<!-- FIXME: This is reliant on https://github.com/reactive-python/reactpy/issues/1071 --> |
18 | 17 |
|
19 |
| -## Production-grade React frameworks |
| 18 | +!!! note |
20 | 19 |
|
21 |
| -### Next.js |
| 20 | + Some of our frameworks are considered _built-in_, meaning that compatibility for these backends are contained within `reactpy.backend.*`. |
22 | 21 |
|
23 |
| -**[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: |
| 22 | + In order to run ReactPy with these frameworks, you will need to run `reactpy.backend.*.configure(...)` on your ASGI application. This command will configure the necessary settings and routes for ReactPy to work properly. |
24 | 23 |
|
25 |
| -<TerminalBlock> |
26 |
| -npx create-next-app |
27 |
| -</TerminalBlock> |
| 24 | + For example, this is how you would configure ReactPy for FastAPI: |
28 | 25 |
|
29 |
| -If you're new to Next.js, check out the [Next.js tutorial.](https://nextjs.org/learn/foundations/about-nextjs) |
| 26 | + ```python linenums="0" |
| 27 | + {% include "../../examples/python/start_a_new_react_project/configure_example.py" %} |
| 28 | + ``` |
30 | 29 |
|
31 |
| -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. |
| 30 | +### FastAPI |
32 | 31 |
|
33 |
| -### Remix |
| 32 | +FastAPI is a high-performance web framework that is designed for speed and efficiency. It is built on top of the asyncio library and uses a number of optimizations to achieve its performance. FastAPI is a good choice for web applications that need to be fast and scalable. |
34 | 33 |
|
35 |
| -**[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: |
| 34 | +!!! example "Terminal" |
36 | 35 |
|
37 |
| -<TerminalBlock> |
38 |
| -npx create-remix |
39 |
| -</TerminalBlock> |
| 36 | + ```bash linenums="0" |
| 37 | + pip install reactpy[fastapi] |
| 38 | + ``` |
40 | 39 |
|
41 |
| -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). |
| 40 | +If you're new to FastAPI, check out the [FastAPI tutorial](https://fastapi.tiangolo.com/tutorial/). |
42 | 41 |
|
43 |
| -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). |
| 42 | +You will need to [configure FastAPI](#built-in-backends) in order to use it with ReactPy. |
44 | 43 |
|
45 |
| -### Gatsby |
| 44 | +### Flask |
46 | 45 |
|
47 |
| -**[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: |
| 46 | +Flask is a microframework that is lightweight and easy to use. It is a good choice for small and simple web applications. Flask does not include many features out of the box, but it is highly customizable and can be extended with a variety of third-party libraries. |
48 | 47 |
|
49 |
| -<TerminalBlock> |
50 |
| -npx create-gatsby |
51 |
| -</TerminalBlock> |
| 48 | +!!! example "Terminal" |
52 | 49 |
|
53 |
| -If you're new to Gatsby, check out the [Gatsby tutorial.](https://www.gatsbyjs.com/docs/tutorial/) |
| 50 | + ```bash linenums="0" |
| 51 | + pip install reactpy[flask] |
| 52 | + ``` |
54 | 53 |
|
55 |
| -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. |
| 54 | +If you're new to Flask, check out the [Flask tutorial](https://flask.palletsprojects.com/en/latest/tutorial/). |
56 | 55 |
|
57 |
| -### Expo (for native apps) |
| 56 | +You will need to [configure Flask](#built-in-backends) in order to use it with ReactPy. |
58 | 57 |
|
59 |
| -**[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: |
| 58 | +### Sanic |
60 | 59 |
|
61 |
| -<TerminalBlock> |
62 |
| -npx create-expo-app |
63 |
| -</TerminalBlock> |
| 60 | +Sanic is a microframework that is designed for speed and performance. It is built on top of the asyncio library and uses a number of optimizations to achieve its performance. Sanic is a good choice for web applications that need to be fast and scalable. |
64 | 61 |
|
65 |
| -If you're new to Expo, check out the [Expo tutorial](https://docs.expo.dev/tutorial/introduction/). |
| 62 | +!!! example "Terminal" |
66 | 63 |
|
67 |
| -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. |
| 64 | + ```bash linenums="0" |
| 65 | + pip install reactpy[sanic] |
| 66 | + ``` |
68 | 67 |
|
69 |
| -<DeepDive> |
| 68 | +If you're new to Sanic, check out the [Sanic tutorial](https://sanicframework.org/en/guide/). |
70 | 69 |
|
71 |
| -#### Can I use React without a framework? |
| 70 | +You will need to [configure Sanic](#built-in-backends) in order to use it with ReactPy. |
72 | 71 |
|
73 |
| -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.** |
| 72 | +### Starlette |
74 | 73 |
|
75 |
| -Here's why. |
| 74 | +Starlette is a lightweight framework that is designed for simplicity and flexibility. It is built on top of the ASGI standard and is very easy to extend. Starlette is a good choice for web applications that need to be simple and flexible. |
76 | 75 |
|
77 |
| -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. |
| 76 | +!!! example "Terminal" |
78 | 77 |
|
79 |
| -**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 client–server 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. |
| 78 | + ```bash linenums="0" |
| 79 | + pip install reactpy[starlette] |
| 80 | + ``` |
80 | 81 |
|
81 |
| -**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). |
| 82 | +If you're new to Starlette, check out the [Starlette tutorial](https://www.starlette.io/tutorial/). |
82 | 83 |
|
83 |
| -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. </DeepDive> |
| 84 | +You will need to [configure Starlette](#built-in-backends) in order to use it with ReactPy. |
84 | 85 |
|
85 |
| -## Bleeding-edge React frameworks |
| 86 | +### Tornado |
86 | 87 |
|
87 |
| -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) |
| 88 | +Tornado is a scalable web framework that is designed for high-traffic applications. It is built on top of the asyncio library and uses a number of optimizations to achieve its scalability. Tornado is a good choice for web applications that need to handle a lot of traffic. |
88 | 89 |
|
89 |
| -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!) |
| 90 | +!!! example "Terminal" |
90 | 91 |
|
91 |
| -### Next.js (App Router) |
| 92 | + ```bash linenums="0" |
| 93 | + pip install reactpy[tornado] |
| 94 | + ``` |
92 | 95 |
|
93 |
| -**[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. |
| 96 | +If you're new to Tornado, check out the [Tornado tutorial](https://www.tornadoweb.org/en/stable/guide/). |
94 | 97 |
|
95 |
| -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. <Pitfall> |
| 98 | +You will need to [configure Tornado](#built-in-backends) in order to use it with ReactPy. |
96 | 99 |
|
97 |
| -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). |
| 100 | +## External Backends |
98 | 101 |
|
99 |
| -</Pitfall> |
| 102 | +### Django |
100 | 103 |
|
101 |
| -<DeepDive> |
| 104 | +[Django](https://www.djangoproject.com/) is a full-featured web framework that provides a batteries-included approach to web development. It includes features such as ORM, templating, authentication, and authorization. Django is a good choice for large and complex web applications. |
102 | 105 |
|
103 |
| -#### Which features make up the React team’s full-stack architecture vision? |
| 106 | +!!! example "Terminal" |
104 | 107 |
|
105 |
| -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. |
| 108 | + ```bash linenums="0" |
| 109 | + pip install reactpy-django |
| 110 | + ``` |
106 | 111 |
|
107 |
| -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: |
| 112 | +If you're new to Django, check out the [Django tutorial](https://docs.djangoproject.com/en/dev/intro/tutorial01/). |
108 | 113 |
|
109 |
| -```js |
110 |
| -// This component runs *only* on the server (or during the build). |
111 |
| -async function Talks({ confId }) { |
112 |
| - // 1. You're on the server, so you can talk to your data layer. API endpoint not required. |
113 |
| - const talks = await db.Talks.findAll({ confId }); |
| 114 | +You will need to [configure Django](https://reactive-python.github.io/reactpy-django/get-started/installation/) in order to use it with ReactPy. |
114 | 115 |
|
115 |
| - // 2. Add any amount of rendering logic. It won't make your JavaScript bundle larger. |
116 |
| - const videos = talks.map((talk) => talk.video); |
| 116 | +### Jupyter |
117 | 117 |
|
118 |
| - // 3. Pass the data down to the components that will run in the browser. |
119 |
| - return <SearchableVideoList videos={videos} />; |
120 |
| -} |
121 |
| -``` |
| 118 | +Jupyter is an interactive computing environment that is used for data science and machine learning. It allows users to run code, visualize data, and collaborate with others in a live environment. Jupyter is a powerful tool for data scientists and machine learning engineers. |
122 | 119 |
|
123 |
| -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: |
| 120 | +!!! example "Terminal" |
124 | 121 |
|
125 |
| -```js |
126 |
| -<Suspense fallback={<TalksLoading />}> |
127 |
| - <Talks confId={conf.id} /> |
128 |
| -</Suspense> |
129 |
| -``` |
| 122 | + ```bash linenums="0" |
| 123 | + pip install reactpy-jupyter |
| 124 | + ``` |
130 | 125 |
|
131 |
| -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. |
| 126 | +If you're new to Jupyter, check out the [Jupyter tutorial](https://jupyter.org/try). |
132 | 127 |
|
133 |
| -</DeepDive> |
| 128 | +You will need to [configure Jupyter](https://github.com/reactive-python/reactpy-jupyter#readme) in order to use it with ReactPy. |
| 129 | + |
| 130 | +### Plotly Dash |
| 131 | + |
| 132 | +Plotly Dash is a web application framework that is used to create interactive dashboards. It allows users to create dashboards that can be used to visualize data and interact with it in real time. Plotly Dash is a good choice for creating dashboards that need to be interactive and informative. |
| 133 | + |
| 134 | +!!! example "Terminal" |
| 135 | + |
| 136 | + ```bash linenums="0" |
| 137 | + pip install reactpy-dash |
| 138 | + ``` |
| 139 | + |
| 140 | +If you're new to Plotly Dash, check out the [Plotly Dash tutorial](https://dash.plotly.com/installation). |
| 141 | + |
| 142 | +You will need to [configure Plotly Dash](https://github.com/reactive-python/reactpy-dash#readme) in order to use it with ReactPy. |
| 143 | + |
| 144 | +!!! info "Deep Dive" |
| 145 | + |
| 146 | + <font size="4">**Can I use ReactPy without a backend framework?**</font> |
| 147 | + |
| 148 | + You can not ReactPy without a backend—this project was designed to be built on-top of existing web frameworks. |
| 149 | + |
| 150 | + Here's why. |
| 151 | + |
| 152 | + You can think of ReactPy as ReactJS server side rendering, but with a Python server. We rely on Python web frameworks and webservers in order to process ReactPy traffic. **This means that you can [use any Python web framework](../learn/creating-backends.md) as a ReactPy backend, as long as it supports the ASGI standard.** As your project grows with every new feature, you may want to switch backends in the future. As a result, we recommend keeping all backend-related logic within hook functions in order to make the "points of integration" between ReactPy and your backend as small as possible. |
| 153 | + |
| 154 | + **If you're building a new app or a site fully with ReactPy, we recommend using your favorite backend combined with [`reactpy-router`](https://github.com/reactive-python/reactpy-router) to create a Single Page Application (SPA).** |
0 commit comments