Skip to content

Commit 6195050

Browse files
committed
start a new react project
1 parent 865c18f commit 6195050

File tree

6 files changed

+144
-91
lines changed

6 files changed

+144
-91
lines changed

README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ In order to set up an environment to develop these docs...
1515
7. Follow the on-screen prompts to view the documentation in your browser
1616
8. You can now edit the markdown files located within `docs/src/` and see the changes in real time
1717

18-
All unfinished tabs are marked via a construction symbol ( 🚧 ).
18+
🚧 : Unfinished tab
19+
🚫 : Tab is blocked from being started due to external factors
1920

2021
Feel free to PR this branch with any changes you make to the documentation. If you have any questions, feel free to ask in the [Discord server](https://discord.gg/uNb5P4hA9X).
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
from fastapi import FastAPI
2+
3+
from reactpy.backend.fastapi import configure
4+
5+
asgi_app = FastAPI()
6+
configure(asgi_app)

docs/src/learn/add-react-to-an-existing-project.md

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
---
2-
title: Add React to an Existing Project 🚧
2+
title: Add React to an Existing Project 🚫
33
---
44

5+
<!--
6+
TODO: Template tag is needed to complete this tab
7+
https://github.com/reactive-python/reactpy/issues/653
8+
-->
9+
510
## Overview
611

712
<p class="intro" markdown>
+94-73
Original file line numberDiff line numberDiff line change
@@ -1,133 +1,154 @@
11
---
2-
title: Start a New React Project 🚧
2+
title: Start a New React Project
33
---
44

55
## Overview
66

77
<p class="intro" markdown>
88

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.
1010

1111
</p>
1212

13-
<Note>
1413

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
1615

17-
</Note>
16+
<!-- FIXME: This is reliant on https://github.com/reactive-python/reactpy/issues/1071 -->
1817

19-
## Production-grade React frameworks
18+
!!! note
2019

21-
### Next.js
20+
Some of our frameworks are considered _built-in_, meaning that compatibility for these backends are contained within `reactpy.backend.*`.
2221

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.
2423

25-
<TerminalBlock>
26-
npx create-next-app
27-
</TerminalBlock>
24+
For example, this is how you would configure ReactPy for FastAPI:
2825

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+
```
3029

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
3231

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.
3433

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"
3635

37-
<TerminalBlock>
38-
npx create-remix
39-
</TerminalBlock>
36+
```bash linenums="0"
37+
pip install reactpy[fastapi]
38+
```
4039

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/).
4241

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.
4443

45-
### Gatsby
44+
### Flask
4645

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.
4847

49-
<TerminalBlock>
50-
npx create-gatsby
51-
</TerminalBlock>
48+
!!! example "Terminal"
5249

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+
```
5453

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/).
5655

57-
### Expo (for native apps)
56+
You will need to [configure Flask](#built-in-backends) in order to use it with ReactPy.
5857

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
6059

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.
6461

65-
If you're new to Expo, check out the [Expo tutorial](https://docs.expo.dev/tutorial/introduction/).
62+
!!! example "Terminal"
6663

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+
```
6867

69-
<DeepDive>
68+
If you're new to Sanic, check out the [Sanic tutorial](https://sanicframework.org/en/guide/).
7069

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.
7271

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
7473

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.
7675

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"
7877

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+
```
8081

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/).
8283

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.
8485

85-
## Bleeding-edge React frameworks
86+
### Tornado
8687

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.
8889

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"
9091

91-
### Next.js (App Router)
92+
```bash linenums="0"
93+
pip install reactpy[tornado]
94+
```
9295

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/).
9497

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.
9699

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
98101

99-
</Pitfall>
102+
### Django
100103

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.
102105

103-
#### Which features make up the React team’s full-stack architecture vision?
106+
!!! example "Terminal"
104107

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+
```
106111

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/).
108113

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.
114115

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
117117

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.
122119

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"
124121

125-
```js
126-
<Suspense fallback={<TalksLoading />}>
127-
<Talks confId={conf.id} />
128-
</Suspense>
129-
```
122+
```bash linenums="0"
123+
pip install reactpy-jupyter
124+
```
130125

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).
132127

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

Comments
 (0)