Skip to content

fix: consistent note object type in Server Components docs#8475

Open
Ashutosh0x wants to merge 1 commit into
reactjs:mainfrom
Ashutosh0x:fix/server-components-note-type
Open

fix: consistent note object type in Server Components docs#8475
Ashutosh0x wants to merge 1 commit into
reactjs:mainfrom
Ashutosh0x:fix/server-components-note-type

Conversation

@Ashutosh0x

Copy link
Copy Markdown

Summary

Fixes the Server Components code examples so the note variable is consistently treated as an object throughout all 3 examples on the page.

Closes #6933

Changes

Client Component example (without Server Components):

  • Changed useState('') to useState(null) (note is an object, not a string)
  • Added null guard before accessing note.authorId
  • Changed {note} to {note.content} in JSX

Server Component example (with Server Components):

  • Changed {note} to {note.content} in JSX

Async Server Component example:

  • Changed {note} to <p>{note.content}</p> in JSX

Why

The note object has properties like .authorId, .id, and .content, but was being:

  1. Initialized as an empty string ''
  2. Rendered directly as {note} which would show [object Object]

This is confusing for developers learning React Server Components.

cc @rickhanlonii @poteto

Fixes reactjs#6933

The Server Components docs page had inconsistent handling of the note variable across 3 code examples. All examples now consistently treat note as an object with .authorId, .id, and .content properties.
@github-actions

Copy link
Copy Markdown

Size changes

Details

📦 Next.js Bundle Analysis for react-dev

This analysis was generated by the Next.js Bundle Analysis action. 🤖

This PR introduced no changes to the JavaScript bundle! 🙌

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Typo]: note should be object or string

1 participant