Skip to content
    SeaCode
    Learning tracksCode ArenaWorkshops & EventsInstructors
    Log inSign up
    ⚛React

    Components and JSX

    • Why React?
    • JSX rules
    • Props
    • Rendering lists and keys
    • Conditional rendering

    State and events

    • Handling events
    • useState: a component's memory
    • Objects and arrays in state
    • Forms and controlled inputs
    • Lifting state up

    Effects and essential hooks

    • useEffect
    • Fetching data
    • useRef
    • Context: data for the whole tree
    • useReducer

    Professional React

    • Writing your own hooks
    • Performance: memo, useMemo and useCallback
    • Suspense and error boundaries
    • What's new in React 19
    • Thinking in React
    • Project: a complete to-do app
    React

    Components and JSX · Lesson 3 of 21

    Props

    Passing data into components, children, and default values.

    8 minutes2 games

    Props are how a parent passes data to a child, like a function's parameters. They arrive as one object, usually destructured right in the signature.

    React
    function CourseCard({ title, hours, price = 0, tags = [] }) {
      return (
        <div style={{ border: "1px solid #ccc", borderRadius: 12, padding: 12, marginBottom: 8 }}>
          <h3 style={{ margin: 0 }}>{title}</h3>
          <p style={{ margin: "4px 0" }}>{hours} hours · {price === 0 ? "Free" : price + " EGP"}</p>
          <small>{tags.join(", ")}</small>
        </div>
      )
    }
    
    function App() {
      return (
        <>
          <CourseCard title="HTML & CSS" hours={12} tags={["web", "beginner"]} />
          <CourseCard title="React" hours={24} price={600} tags={["web"]} />
        </>
      )
    }

    Note: text is passed in quotes, title="React"; anything else (a number, array, object, function) goes in { }. price = 0 is a default when the parent sends nothing.

    children

    React
    function Panel({ title, children }) {
      return (
        <section style={{ background: "#eef6ff", padding: 12, borderRadius: 12 }}>
          <strong>{title}</strong>
          <div>{children}</div>
        </section>
      )
    }
    
    function App() {
      return (
        <Panel title="Tip">
          <p>Anything between the tags arrives as <code>children</code>.</p>
        </Panel>
      )
    }

    App: <CourseCard title="React" hours={24} />

    props = { title: "React", hours: 24 }

    CourseCard reads and renders

    Data flows one way: from parent to child.

    Important

    Props are read-only. A component never modifies its props (props.title = … is wrong). If a child needs to change something, the parent passes it a function as a prop and the child calls it (see the lifting-state lesson).

    Quick question

    How do you pass 24 as a prop so it arrives as a number, not text?

    Interview question

    What's the difference between props and state?

    Exercise

    Finish Greeting so it shows Hi, NAME!, with NAME defaulting to friend. The page should show Hi, Mariam! then Hi, friend!.

    The page should show:
    Hi, Mariam!
    Hi, friend!
    React
    function Greeting(props) {
      return <p>Hi!</p>
    }
    
    function App() {
      return (
        <div>
          <Greeting name="Mariam" />
          <Greeting />
        </div>
      )
    }

    Learn more from

    • react.dev: Passing props to a componentreact.dev
    • react.dev: Choosing the state structurereact.dev
    • MDN: Destructuring assignmentdeveloper.mozilla.org

    Played 0 of 2 games

    Sign in to save your progress and earn XP.

    PreviousJSX rulesNextRendering lists and keys
    SeaCode

    Learn to code for real, online or at our branch in front of Cairo University, Giza.

    Learn

    • All courses
    • Interactive tutorials
    • Interview practice problems
    • Mock interview
    • Learning tracks
    • Code Arena
    • Workshops & Events
    • Knowledge library
    • Team projects

    Your account

    • Log in
    • Sign up
    • Learning plan
    • Certificates
    • Site map

    Contact us

    • WhatsApp
    • 010 9094 1104
    • In front of Cairo University, Giza

    © 2026 SeaCode. All rights reserved.