Last active
December 31, 2023 14:59
-
-
Save nickserv/146fa055e89cc1feedefd67666a2e8db to your computer and use it in GitHub Desktop.
RSC streaming using recursive promises https://twitter.com/shuding_/status/1681373460860108810
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
async function Row({ chunk }) { | |
const { next, value, done } = await chunk | |
if (done) return null | |
return ( | |
<> | |
{value} | |
<Row chunk={next} /> | |
</> | |
) | |
} | |
async function read(reader) { | |
const { value, done } = await reader.read() | |
return { | |
value, | |
done, | |
next: done ? null : read(reader) | |
} | |
} | |
export default async function Home() { | |
const { body } = await fetch('https://example.com') | |
return <Row chunk={read(body.getReader())} /> | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment