Single logo
  • Courses
  • Blog
  • About
Join on SkoolJoin on Skool

In this topic

React
  • One Request, Two Answers: the Same Post as an HTML Page and as JSON
  • A Blog Design from a Prompt: Downloading Figma Make Code and Reading App.tsx and BlogCard.tsx
  • How a Web Page Works: HTML Tags, Elements and Attributes
  • Semantic HTML: header, nav, main, aside and footer as Page Landmarks
  • HTML Forms: Labels, Names, Input Types and Where the Data Goes (GET vs POST)
  • CSS Basics: Selectors, Which Rule Wins, and the Box Model
  • CSS Flexbox vs Grid: A Nav Bar, a Card Row and a Dashboard
  • Responsive CSS: Viewport, Mobile-First Media Queries, clamp() and Dark Mode with Tokens
  • JavaScript for People Who Already Code: Syntax, Modules and Five Surprises
  • JavaScript Arrays the Functional Way: map, filter, reduce, find, sort and Object.entries
  • Async JavaScript: Promises, async/await, fetch and Promise.all
  • JavaScript in the Page: the DOM, querySelector and Events
  • npm, package.json and Vite: What npm install Fetches and How Vite Serves and Builds Your Page
  • TypeScript Essentials: Types Checked, Then Erased (Interfaces, Unions, Generics)
  • Why React, JSX and Components: The Page as a Function of Data
  • React Props and Composition: Data Down, Calls Up, Children in the Slot
  • Routing With React Router: One Page, Many Addresses
  • React Component Tests With Vitest and Testing Library: Test What the User Sees
  • End-to-End Tests for a React App With Playwright: A Full Dress Rehearsal
  • Why AI-Built Websites All Look the Same, and Four Levels That Fix It
  • Visual Hierarchy, Spacing and the 8-Point Grid: Tell the Eye What to Read First
  • Colour, Contrast and Dark Palettes: 60-30-10, Semantic Tokens and Ratios You Can Compute
  • Typography That Sells: Type Scale, Line Length and Free Font Pairings
  • The UI Element Catalogue: Buttons to Toasts, Their Jobs, States and shadcn/ui Names
  • Design Tokens: Primitive and Semantic Tokens, from Figma to CSS to Tailwind
  • Tailwind CSS 4 in React: Utility Classes, Responsive Prefixes, Hover and Dark Mode
  • shadcn/ui in React: Components You Own, Edit and Commit
  • Design Tokens to a Tailwind Theme: Light and Dark Mode with @theme inline
  • Motion in React: Entrance, Hover, Exit and Layout Animations
  • A React Dashboard: Stat Cards, a Recharts Line Chart and a Sortable Table
  • Accessibility in Practice: Dialogs, Menus and the Keyboard in React
  • Reference-Driven Design: Extract a DESIGN.md From a Site You Admire and Build From It
  • Components, Variants and Variables: One Design System in Figma and in CSS
  • Figma MCP Server: Build a React Component From a Frame, Then Write It Back
  • Claude Design: From a Brief to a Clickable Prototype, Then Hand It Off to Claude Code
  • Critiquing AI-Generated UI: Six Checks for Every Screen
  • The AI Design Landscape: Prompt to UI, Prompt to App, and Design to Code
  • Your Brand Rules Folder: One Folder Every AI-Built Page Follows
  • The Best-Practice UI Prompt: Plain Sentences That Beat the Average AI Page
  • UI Ideas From Figma Make, Google Stitch and ChatGPT: One Prompt, Three Designs
  • Google Stitch From a Sketch or Screenshot: Show the Layout, Say What to Keep
  • Stitch to Figma to Code: Turn a Stitch Screen Into Code That Uses Your Tokens
  • Figma Make: Prompt to Prototype With a Four-Part Prompt
  • Upgrade a Dated UI From One Screenshot (or a Reference Image)
  • States and Feedback: Make Every Click Get an Answer
  • A Design-Loop Skill: Claude Screenshots, Scores and Fixes Its Own UI
  • Copy Without the AI Tells: A Copy Pass on a Landing Page
  • React State, Events, Lists and Conditional Rendering: Follow One Click
  • React useEffect: When It Runs, What Cleanup Is For, and When You Don't Need One
  • Lifting State Up, Refs and React DevTools: Put State Where It Is Needed
  • Forms and Actions in React 19: Controlled Inputs, Form Actions, useActionState and useFormStatus
  • React Context and Custom Hooks: Share One Value, Reuse the Logic
  • Server State With TanStack Query: One Key, One Request, One Cache
  • Mutations and Optimistic Updates in TanStack Query: Change Data, Then Tell the Cache
  • Generate TypeScript Types, Query Hooks and Zod From an OpenAPI Spec With Orval
  • A Mock Backend in the Browser With Mock Service Worker, Generated From the Spec
  • A React Client for a FastAPI API: The CORS Wall, CORSMiddleware and the Vite Proxy
  • Forms With React Hook Form and Zod: The API's Rules in the Browser, the Server's Errors Under the Field
  • JWT Auth in a React Client With a FastAPI Backend: Log In, Carry the Token, Let the Server Decide
  1. Blog
  2. /
  3. React
  4. /
  5. Fundamentals

React Props and Composition: Data Down, Calls Up, Children in the Slot

Follow props from a parent's tag into a component and onto the page: one props object, destructuring, an interface with an optional prop and a default, the read-only rule, a callback that goes back up, and the children slot that lets one Card hold anything.

Chaand Sheikh

·27 November 2026·Updated 28 November 2026Fundamentals

What you will learn

  • Read props as the one object React passes to a component
  • Type props with an interface, optional props and default values
  • Pass a function down so a child can ask its parent for a change
  • Build a page from small pieces with the children slot

Before you start

  • React components and JSX (see Why React, JSX and Components)
  • TypeScript basics: types and interfaces

A component is a function, and props are its arguments. A parent writes a tag with attributes, React gathers them into one object, and calls the component with it. That one idea explains almost everything in this article: how data reaches a component, why a child can't change it, and how a big page gets built from small pieces.

The examples come from a small task app with a TaskCard, a Card box, a Board and a DoneButton. The outputs are from the lecture's own demo scripts.

Attributes become one props object

// Example 1: a component and its props
interface TaskCardProps {
  title: string
  owner: string
  done?: boolean // optional: it has a default
}

// React hands ALL the attributes over as one object
export function TaskCard(props: TaskCardProps) {
  console.log('TaskCard got', props)
  const { title, owner, done = false } = props

  return (
    <div className="card">
      <h3>{title}</h3>
      <p>Owner: {owner}</p>
      <p>{done ? 'Done' : 'To do'}</p>
    </div>
  )
}

A demo renders <TaskCard title="Write report" owner="Emma" done={true} />. Notice the two kinds of value. "Write report" in quotes is a string. {true} in curly braces is a real JavaScript boolean, not the text "true". Line 10 logs what the function receives:

TaskCard got { title: 'Write report', owner: 'Emma', done: true }
page: Write report | Owner: Emma | Done

Three attributes, one object, passed as the single argument.

Destructuring: one object, three names

Writing props.title everywhere gets long, so line 11 destructures the object: const { title, owner, done = false } = props. Each key gets its own name, and the JSX drops those values into the page. They are the same values as props.title and props.owner, with shorter names.

An interface describes the shape

Lines 2 to 6 are interface TaskCardProps. Think of it as a printed form with three blanks: title is a string, owner is a string, done is a boolean. The question mark after done means a tag may leave it out. TypeScript checks every TaskCard tag in the project against this shape. Here are two wrong tags:

// What tsc says when a tag does not fit the props.
import { TaskCard } from '../src/TaskCard'

// owner is left out
export const a = <TaskCard title="Pay invoice" />

// done gets a string, not a boolean
export const b = (
  <TaskCard title="Pay invoice" owner="Olivia"
    done="yes" />
)
scripts/break-types.tsx(5,19): error TS2741: Property 'owner' is missing in type '{ title: string; }' but required in type 'TaskCardProps'.
scripts/break-types.tsx(10,5): error TS2322: Type 'string' is not assignable to type 'boolean | undefined'.

A missing prop and a wrong type both fail before any code runs, and the compiler tells you which prop and which line.

One component, different props

Here is where props pay off. App uses TaskCard three times inside a Card:

// Composition: the page built from small components
import { Board } from './Board'
import { Card } from './Card'
import { TaskCard } from './TaskCard'

export default function App() {
  return (
    <>
      <Card heading="This week">
        <TaskCard title="Write report" owner="Emma"
          done={true} />
        <TaskCard title="Book flights" owner="Jack"
          done={false} />
        <TaskCard title="Pay invoice"
          owner="Olivia" />
      </Card>
      <Card heading="Notes">
        <p>Stand-up is at ten.</p>
      </Card>
      <Card heading="Today">
        <Board />
      </Card>
    </>
  )
}

React builds a different props object for each tag and calls the same function once per tag. The fourth line comes from the Board further down the page:

TaskCard got { title: 'Write report', owner: 'Emma', done: true }
TaskCard got { title: 'Book flights', owner: 'Jack', done: false }
TaskCard got { title: 'Pay invoice', owner: 'Olivia' }
TaskCard got { title: 'Call Jack', owner: 'Emma', done: false }
card: Write report - Done
card: Book flights - To do
card: Pay invoice - To do

One design, three cards, no copied markup. Change TaskCard once and all of them change.

A default value for a missing prop

Look at the third line of that output. Pay invoice has no done attribute, so its props object simply has no done key. Without help, done would be undefined. The default in the destructuring, done = false, fills the gap, so the card says To do. The default is used only when the prop is missing. When the parent passes done, the parent wins.

Props flow one way: down

Data down, calls up Board owns done (state), handleDone TaskCard reads done, shows To do / Done DoneButton click runs onDone(title) props: done props: onDone call goes up
A parent passes props down. A child reads them and never changes them. To ask for a change, it calls a function the parent passed down.

Props ride along the branches of the tree, always from parent to child. The other direction doesn't work: a TaskCard can't reach up and change what App gave it.

What if a child changes its props?

// What happens when a child changes its own props.
import { show } from './screen'

function Rename(props: { title: string }) {
  props.title = 'Changed' // not allowed
  return <h3>{props.title}</h3>
}

try {
  await show(<Rename title="Write report" />)
} catch (e) {
  const err = e as Error
  console.log(`${err.name}: ${err.message}`)
}
TypeError: Cannot assign to read only property 'title' of object '#<Object>'

In development React freezes the props object, so the assignment on line 5 throws. The parent's title stays Write report. Props are read only.

A function as a prop: the callback goes up

So how does anything change? The parent owns the data and passes down a function to change it. Here is Board:

// Example 3: the parent passes a function down
import { useState } from 'react'
import { DoneButton } from './DoneButton'
import { TaskCard } from './TaskCard'

export function Board() {
  // state: data the parent owns, kept by React
  const [done, setDone] = useState(false)

  function handleDone(title: string) {
    console.log('Board heard:', title)
    setDone(true)
  }

  return (
    <div>
      <TaskCard title="Call Jack" owner="Emma"
        done={done} />
      <DoneButton title="Call Jack"
        onDone={handleDone} />
    </div>
  )
}

Line 8 keeps done in state, data the parent owns and React keeps between renders (state gets its own article next). handleDone is a function, and a function is a value like any other, so line 20 hands it down as onDone. The child:

// Example 3: the child gets a function as a prop
interface DoneButtonProps {
  title: string
  // a function the parent hands down
  onDone: (title: string) => void
}

export function DoneButton(props: DoneButtonProps) {
  const { title, onDone } = props

  // the child cannot change the data, so it calls up
  return (
    <button onClick={() => onDone(title)}>
      Mark done
    </button>
  )
}

Line 5 types onDone as a function that takes a string and returns nothing. On a click, line 13 calls it with the title, and that call runs Board's handleDone. Here is one click, followed in the demo:

TaskCard got { title: 'Call Jack', owner: 'Emma', done: false }
page: Call Jack | Owner: Emma | To do
click: Mark done
Board heard: Call Jack
TaskCard got { title: 'Call Jack', owner: 'Emma', done: true }
page: Call Jack | Owner: Emma | Done

Board sets done to true, React renders Board again, and new props come down to TaskCard. The child never touched the data. It asked, and the parent made the change.

children: a slot the parent fills

// Example 4: children - a slot the parent fills
import type { ReactNode } from 'react'

interface CardProps {
  heading: string
  children: ReactNode // what sits between the tags
}

export function Card(props: CardProps) {
  const { heading, children } = props

  return (
    <section className="box">
      <h2>{heading}</h2>
      {children}
    </section>
  )
}

Whatever sits between <Card> and </Card> arrives in props as children, typed as ReactNode (anything React can draw), and lands where line 15 puts it. In App, one Card holds three task cards, one holds a paragraph, and one holds the Board. The demo prints what landed in each slot:

Card "This week" children: div, div, div
Card "Notes" children: p
Card "Today" children: div

One Card, three different insides. This is composition: small pieces that don't need to know what they will hold.

Common mistakes

  • Writing done="true". That is the string "true". Use done={true} for a boolean.
  • Changing props.something inside a child. Ask the parent with a function prop instead.
  • Calling the callback while rendering: onClick={onDone(title)} runs immediately. Pass a function: onClick={() => onDone(title)}.
  • Forgetting to render {children}, so whatever the parent put between the tags never shows.

Recap

IdeaWhat to remember
PropsThe tag's attributes, gathered into one object, passed as the one argument
InterfaceNames every prop and its type; ? marks an optional prop
Defaultdone = false in the destructuring fills a missing prop
DirectionProps go down and are read only
Function propThe child calls it to ask the parent for a change
childrenEverything between the tags, placed where {children} sits

Try it yourself: add a fourth TaskCard with a new owner, then give Card an optional footer prop and render it under the children. The next article, state, events, lists and conditional rendering, looks at the useState line in Board properly.

Keep going in React · 16 of 59

Previous
Why React, JSX and Components: The Page as a Function of Data
Next post
Routing With React Router: One Page, Many Addresses
Community · Free to join
Single logo

StudyEasy AI Community

Hosted onSkool

Learn AI engineering, share what you build, and connect with other learners.

  • Free resources: lesson files, notebooks and code

  • Ask questions and join engineering discussions

  • Meet real people learning and building with AI

Join free on Skool

Related course on Udemy

The Python Architect Masterclass: Full Stack to AI Engineer

Python, Django, FastAPI, React, Docker, AWS, LLMs, RAG, agents and MCP, from first steps to AI engineer.View on Udemy ↗: The Python Architect Masterclass: Full Stack to AI Engineer (paid course, opens in a new tab)

Related posts

One Request, Two Answers: the Same Post as an HTML Page and as JSON

Ask a Django blog for the same post twice: once as a 12,731-byte HTML page built by a template, once as 2,976 bytes of JSON built by a serializer. Compare the headers, see who builds the page, and why the server still owns every write.

A Blog Design from a Prompt: Downloading Figma Make Code and Reading App.tsx and BlogCard.tsx

Make a blog design from a prompt in Figma Make, download src.zip, unzip it with Python's zipfile module, and read the two files that matter: App.tsx with its selectedPost state and BlogCard.tsx with its props.

How a Web Page Works: HTML Tags, Elements and Attributes

A web page is a text file full of labelled pieces. Learn tags, attributes and nesting with three tiny pages, and see what breaks when an attribute or a closing tag is wrong.

Semantic HTML: header, nav, main, aside and footer as Page Landmarks

The same page written as div soup and with semantic tags looks identical, but only one gives screen readers and search engines landmarks and an outline. Plus tables, div, span and the one-main rule.

On this page

  • Attributes become one props object
  • Destructuring: one object, three names
  • An interface describes the shape
  • One component, different props
  • A default value for a missing prop
  • Props flow one way: down
  • What if a child changes its props?
  • A function as a prop: the callback goes up
  • children: a slot the parent fills
  • Common mistakes
  • Recap
Community · Free to join
Single logo

StudyEasy AI Community

Hosted onSkool

Learn AI engineering, share what you build, and connect with other learners.

  • Free resources: lesson files, notebooks and code

  • Ask questions and join engineering discussions

  • Meet real people learning and building with AI

Join free on Skool

Related course on Udemy

The Python Architect Masterclass: Full Stack to AI Engineer

Python, Django, FastAPI, React, Docker, AWS, LLMs, RAG, agents and MCP, from first steps to AI engineer.View on Udemy ↗: The Python Architect Masterclass: Full Stack to AI Engineer (paid course, opens in a new tab)

Single logo

Empowering Education, One Course at a Time

About
About usContact us
Legal
Terms of UsePrivacy Policy

© 2026 StudyEasy Organization. All rights reserved.