Skip to content

Commit 2d49ce7

Browse files
update docs
1 parent b6d9fd5 commit 2d49ce7

File tree

1 file changed

+23
-7
lines changed

1 file changed

+23
-7
lines changed

docs/guides/streaming-server-rendering.md

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ React on Rails Pro supports streaming server rendering using React 18's latest A
77
- React on Rails Pro subscription
88
- React 18 or higher (experimental version)
99
- React on Rails v15.0.0-alpha.0 or higher
10+
- React on Rails Pro v4.0.0.rc.5 or higher
1011

1112
## Benefits of Streaming Server Rendering
1213

@@ -29,23 +30,32 @@ First, ensure you're using React 18's experimental version in your package.json:
2930
}
3031
```
3132

33+
> Note: Check the React documentation for the latest release that supports streaming.
34+
3235
2. **Prepare Your React Components**
3336

3437
You can create async React components that return a promise. Then, you can use the `Suspense` component to render a fallback UI while the component is loading.
3538

3639
```jsx
3740
// app/javascript/components/MyStreamingComponent.jsx
38-
3941
import React, { Suspense } from 'react';
4042

43+
const fetchData = async () => {
44+
// Simulate API call
45+
const response = await fetch('api/endpoint');
46+
return response.json();
47+
};
48+
4149
const MyStreamingComponent = () => {
4250
return (
43-
<header>
44-
<h1>Streaming Server Rendering</h1>
45-
</header>
46-
<Suspense fallback={<div>Loading...</div>}>
47-
<SlowDataComponent />
48-
</Suspense>
51+
<>
52+
<header>
53+
<h1>Streaming Server Rendering</h1>
54+
</header>
55+
<Suspense fallback={<div>Loading...</div>}>
56+
<SlowDataComponent />
57+
</Suspense>
58+
</>
4959
);
5060
};
5161

@@ -55,9 +65,15 @@ const SlowDataComponent = async () => {
5565
};
5666

5767
export default MyStreamingComponent;
68+
```
69+
70+
```jsx
71+
// app/javascript/packs/registration.jsx
72+
import MyStreamingComponent from '../components/MyStreamingComponent';
5873

5974
ReactOnRails.register({ MyStreamingComponent });
6075
```
76+
6177
3. **Add The Component To Your Rails View**
6278

6379
```erb

0 commit comments

Comments
 (0)