liveBook · Manning

Prop

As explained in React in Depth

A React prop is an input value passed to a component to configure its rendering or behavior.

A prop is an input value passed to a component to configure its rendering or behavior. Props describe component inputs, but they do not independently determine whether the component re-renders: a parent render re-renders its child regardless of which props it receives. section 3.1.1

Treat props as inputs, not as a standalone rendering-control mechanism:

  • Expect a child to re-render when its parent re-renders, even when the child receives no props or unchanged props. section 3.1.1
  • Do not expect changing a value held in a ref to update the UI or trigger a render merely because that value is passed as a prop. section 3.1.1
  • Inspect and manipulate props during debugging; React Developer Tools applies changes immediately and causes the selected component to re-render. section 4.4.3

Testing the prop–render relationship

Render a Rerenderable child beneath a stateful parent and update the parent with setCount; the child re-renders even without props. Then pass count.current from a ref and increment the ref directly; the prop value changes, but the child does not re-render because no render was triggered. section 3.1.1

Listing 3.1 A component that highlights re-renders
import { useEffect } from "react";
import { useRef } from "react";
export function Rerenderable() {
  const isFirst = useRef(true);
  useEffect(() => {
    isFirst.current = false;    #1
  }, []);
  const style = #2
    { color: isFirst.current ? "red" : "blue" };    #2
  const text = isFirst.current  #2
    ? "First render" : "Not first render";    #2
  return <p style={style}>{text}</p>;
}

Use the render-highlighting component to make first and subsequent renders visible, then compare it with the two parent components that change state or ref-held prop values. section 3.1.1

How React in Depth covers it

How deep it goes
Explains parent-driven re-renders, ref mutation, and live inspection, but stops short of a broader rendering-performance strategy.
Examples
Uses a render-highlighting component, state and ref buttons, and a dark-mode application inspected through React Developer Tools.
What you can do after
Diagnose/debug with render probes and React Developer Tools to distinguish prop changes from the events that actually trigger renders.
How it connects
Connects props to parent components, state, refs, re-rendering, memoization, context, and React Developer Tools.

Also explained in

Compare how 5 books explain prop →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of React in Depth. The section links point to the parts of the book it draws on.