Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions src/content/reference/rsc/server-components.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,18 +100,22 @@ Without Server Components, it's common to fetch dynamic data on the client in an
```js
// bundle.js
function Note({id}) {
const [note, setNote] = useState('');
const [note, setNote] = useState(null);
// NOTE: loads *after* first render.
useEffect(() => {
fetch(`/api/notes/${id}`).then(data => {
setNote(data.note);
});
}, [id]);

if (note == null) {
return null;
}

return (
<div>
<Author id={note.authorId} />
<p>{note}</p>
<p>{note.content}</p>
</div>
);
}
Expand Down Expand Up @@ -155,7 +159,7 @@ async function Note({id}) {
return (
<div>
<Author id={note.authorId} />
<p>{note}</p>
<p>{note.content}</p>
</div>
);
}
Expand Down
Loading