StoicBuilder

HandbookII the ForumComponents and props

IIthe Forum, The shape of an app

Components and props

1 min readUpdated 28 November

In plain words

A component is a reusable piece of screen, like a post card or a button, and props are the values you hand it each time you use it.

Where you see it

Chirp's feed shows fifty posts, but there is only one PostCard file. The feed uses it fifty times, handing each copy a different author, text and like count, written like an HTML tag with a capital letter: <PostCard author="maya" />.

components/PostCard.tsxbrowser
type Props = { author: string; text: string; likes: number }; export function PostCard({ author, text, likes }: Props) { return <article><b>{author}</b> {text} <span>{likes} likes</span></article>;} // in the feed: <PostCard author="maya" text="Hello" likes={3} />
One component, many posts. The props fill in the blanks.

What goes wrong

  1. Three near-copies of the same component

    Ask for a profile page and you may get PostCard, PostCard2 and ProfilePostCard, all nearly identical. Fix a bug in the first and the other two keep it.

  2. Changing a prop inside the component

    Props flow one way, from parent to child, and React treats them as read-only. To change a value, the child calls a function the parent passed down, such as onLike.

    props.likes = props.likes + 1;
  3. Passing one value through five layers

    When a prop travels through components that never use it, one careless edit breaks the chain. Developers call this prop drilling, and it usually means the value needs a shared home.

What to tell your agent

Copy this into Lovable, Bolt, Cursor or any agent
Before building this screen, check the components folder for one that already does the job and reuse it with new props. If you do create a new component, tell me its name, the props it takes and every place it's used.

Quick check

Sign in to earn +10 XP for it

You make the author's name bold in Chirp's PostCard file. What changes on the feed?

Got a prompt that touches components and props?

Paste it. You get a better prompt first, then the cards that explain it.

Check your own prompt

Free, no sign-up.