Props, State and Events

Harry · 28 Sep 2026 · 1 views
Log in to track your progress and mark lessons complete.

Props: Data Flowing Down

function BookCard({ title, price, free }) {
  return (
    <div>
      <h3>{title}</h3>
      <p>{free ? "Free PDF" : `Rs.${price}`}</p>
    </div>
  )
}

Props are read-only inputs. Never mutate them - lift changes up via callbacks.

State with useState

const [query, setQuery] = useState("")
const [count, setCount] = useState(0)
// update based on previous value:
setCount(c => c + 1)

Events

<input value={query} onChange={e => setQuery(e.target.value)} />
<button onClick={() => setCount(c => c + 1)}>+1</button>

Controlled Inputs Pattern

Input value always mirrors state (value + onChange). One source of truth kills entire bug categories in forms.

Component tree with props flowing down

Key Points

  • Props down, events up - the core React data flow.
  • useState for anything the UI must react to.
  • Functional updates (c => c + 1) inside rapid events.
Share this post:

Comments (0)

Please login or register to comment.

Create a free account to keep reading

You've enjoyed a free tutorial! Register (it's free) to unlock every tutorial, track your progress and save code.

or sign in with your account

Already have an account? Log in