Skip to content

Commit 55e20c8

Browse files
committed
Docs
1 parent 5c933d9 commit 55e20c8

File tree

1 file changed

+24
-21
lines changed

1 file changed

+24
-21
lines changed

README.md

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ pip install react
5050
Basic usage
5151
-----------
5252

53-
python-react provides an interface to a render server which is capable of rendering React components.
53+
python-react provides an interface to a render server which is capable of rendering React components with data
54+
from your python process.
5455

5556
Render requests should provide a path to a JS file that exports a React component. If you want to pass
5657
data to the component, you can optionally provide a second argument that will be used as the component's
@@ -74,12 +75,12 @@ If the object is coerced to a string, it will emit the value of the `markup` att
7475

7576
### Setting up a render server
7677

77-
Render servers are typically Node.js processes which sit alongside the python process and respond to network requests.
78+
Render servers are typically Node.js processes which sit alongside the python process and respond to network requests.
7879

7980
To add a render server to your project, you can refer to the [basic rendering example](examples/basic_rendering)
8081
for a simple server that will cover most cases. The key files for the render server are:
81-
- [server.js](examples/basic_rendering/server.js) the server's source code
82-
- [package.json](examples/basic_rendering/package.json) the server's dependencies, installable with
82+
- [server.js](examples/basic_rendering/server.js) - the server's source code
83+
- [package.json](examples/basic_rendering/package.json) - the server's dependencies, installable with
8384
[npm](http://npmjs.com)
8485

8586

@@ -92,10 +93,10 @@ and downsides.
9293
- [Webpack](https://webpack.github.io) is currently the recommended build tool for frontend projects. It can
9394
compile your files into browser-executable code and provides a variety of tools and processes which can
9495
simplify complicated workflows.
95-
- [Browserify](http://browserify.org/) is another popular tool, which has a lot of cross-over with webpack. It
96+
- [Browserify](http://browserify.org/) is another popular tool and has a lot of cross-over with webpack. It
9697
is argurably the easiest of the two to use, but it tends to lag behind webpack in certain functionalities.
9798

98-
For React projects, you'll find that webpack is the usual recommendation - hot module replacement,
99+
For React projects, you'll find that webpack is the usual recommendation. Webpack's hot module replacement,
99100
code-splitting, and a wealth of loaders are the features typically cited.
100101
[react-hot-loader](https://github.com/gaearon/react-hot-loader) is a particularly useful tool as it allows
101102
changes to your components to be streamed live into your browser.
@@ -111,9 +112,10 @@ Both projects can perform the same task of integrating webpack's output. django-
111112
reason about, it aims to do one thing and do it well. python-webpack's more complex, but offers more features.
112113

113114
Note: older versions of this library used to provide tools for integrating React into your frontend. While
114-
those tools tended to provide some conveniences, they also overly complicated deployments, limited the
115-
functionalities that you could apply, and locked you in to a limited workflow which was contrary to React's
116-
best practices. If you want to persist with the worflow previously offered, the [self-mounting components example](examples) illustrates the functionality.
115+
they provided some conveniences they also overly complicated deployments, limited the functionalities that
116+
you could apply, and locked you in to a workflow which was contrary to React's best practices. If you want to
117+
persist with the worflow previously offered, the [self-mounting components example](examples) illustrates the
118+
wiring necessary to achieve comparable functionality.
117119

118120

119121
render_component
@@ -135,7 +137,7 @@ render_component(
135137

136138
# An optional dictionary of data that will be passed to the renderer
137139
# and can be reused on the client-side.
138-
data={
140+
props={
139141
'foo': 'bar'
140142
},
141143

@@ -160,19 +162,20 @@ accepts the `path`, `data`, and `to_static_markup` arguments.
160162
Render server
161163
-------------
162164

163-
Earlier versions of this library used to run the render server as a subprocess, this tended to make
164-
development easier, but also introduced instabilities and inexplicable behaviour. To avoid these issues
165-
python-react now relies on externally managed process.
165+
Earlier versions of this library would run the render server as a subprocess, this tended to make development
166+
easier, but introduced instabilities and opaque behaviour. To avoid these issues python-react now relies on
167+
externally managed process. While managing extra processes can add more overhead initially, it avoids pain down
168+
the track.
166169

167170
If you only want to run the render server in particular environments, change the `RENDER` setting to
168-
False. When `RENDER` is False, the render server is not used, but the similar objects are returned
169-
with the `markup` attribute as an empty string.
171+
False. When `RENDER` is False, the render server is not used directly, but it's wrapper will return similar
172+
objects with the `markup` attribute as an empty string.
170173

171174

172175
### Usage in development
173176

174-
In development environments, it's often easiest to set `RENDER` to False. This ensures that the render
175-
server will not be used, hence you only need to manage your python process.
177+
In development environments, it can be easiest to set the `RENDER` setting to False. This ensures that the
178+
render server will not be used, hence you only need to manage your python process.
176179

177180
Be aware that the render servers provided in the example and elsewhere rely on Node.js's module system
178181
which - similarly to Python - caches all modules as soon as they are imported. If you use the render
@@ -187,14 +190,14 @@ In production environments, you should ensure that `RENDER` is set to True.
187190
You will want to run the render server under whatever supervisor process suits your need. Depending on
188191
your setup, you may need to change the `RENDER_URL` setting to reflect your setup.
189192

190-
Requests are sent to the render server as POST requests.
191-
192-
The render server connector that ships with python-react adds a `?hash=<SHA1>` parameter to the url. The
193+
When the render server wrapper connects to the JS process, it adds a `?hash=<SHA1>` parameter to the url. The
193194
hash parameter is generated from the serialized data that is sent in the request's body and is intended
194195
for consumption by caching layers.
195196

196197
Depending on your load, you may want to put a reverse proxy in front of the render server. Be aware that
197-
many reverse proxies are configured by default to **not** cache POST requests.
198+
render server requests are sent as POST requests and many reverse proxies are configured by default to
199+
**not** cache POST requests.
200+
198201

199202
### Overriding the renderer
200203

0 commit comments

Comments
 (0)