← Learning Hub
Beginner

Props

Props (short for properties) pass data into a component, like attributes on an HTML tag. They make one component show different data.

A product card component is useful only if it can show different products. Props make that possible: the parent passes the details (name, price, image) and the card displays whatever it receives. It's exactly like a function's parameters - same code, different inputs.

Data in React flows one way: down from parent to child through props. This makes apps easier to understand - to find where a value comes from, you just look up the tree. Props can be any JavaScript value: text, numbers, arrays, objects, even functions (which is how children tell parents that something happened).

Example
<!DOCTYPE html>
<html>
  <body>
    <div id="root"></div>

    <script src="https://unpkg.com/react@18.3.1/umd/react.development.js"></script>
    <script src="https://unpkg.com/react-dom@18.3.1/umd/react-dom.development.js"></script>
    <script src="https://unpkg.com/@babel/standalone@7.24.7/babel.min.js"></script>

    <script type="text/babel">
      function Product(props) {
        return (
          <div style={{ border: "1px solid #ccc", padding: 10, margin: 6 }}>
            <b>{props.name}</b> - Rs {props.price}
          </div>
        );
      }

      function App() {
        return (
          <div>
            <Product name="Headphones" price={1299} />
            <Product name="Phone cover" price={199} />
            <Product name="Power bank" price={899} />
          </div>
        );
      }

      ReactDOM.createRoot(document.getElementById("root")).render(<App />);
    </script>
  </body>
</html>
▶ Try it yourself

You can also unpack props by name: function Product({ name, price }). Then use name and price directly.

Props are read-only. A component must not change its own props. To change data, use state (next lesson).
Key points
  • Props pass data from a parent into a child component.
  • Read them as a function parameter: function Card({ name, price }).
  • Props are read-only; data flows down.

📝 Test yourself

1. What are props used for?
2. Can a component change its own props?
3. Pass the number 499 as the price prop:
<Product price= />