Pareto provides first-class support for stream rendering.
We assume that you already have experience using stream rendering. If not, you can refer to these articles to understand what stream rendering is.
Based on experience, we only need to stream the requests of modules with slow interfaces. First, let's define the request method and key value.
Pareto exports a promiseMap object to maintain the promise status of each request corresponding to the key value. Let's set it up.
A well-known joke is: React needs to maintain consistency between the first render on the server and the client, and we also need to synchronize the promise status between the server and the client.
Oh heavens! We've finally arrived here. By using use and suspence in React to consume our request promises, we can achieve stream transmission.
The use
hook was only introduced in React 19, so for React 18, you need to use the use
function exported from Pareto
. Note that it only implements the ability to consume promises.