Skip to content
Home Tutorials Roadmaps Courses
Log in Join free
Tutorials React Components & Props
React Intermediate FREE

Components & Props

Lesson 1 of 17 Intermediate Interactive

React components are JavaScript functions that return JSX. They accept props (properties) as inputs.

Props are read-only — a component cannot modify its own props.

Syntax

REACT
function Greeting({ name, age }) {
    return (
        <div>
            <h2>Hello, {name}!</h2>
            <p>Age: {age}</p>
        </div>
    );
}

<Greeting name="John" age={25} />
Components with Props
REACT
function Greeting({ name, age }) {
    return (
        <div className="greeting">
            <h2>Hello, {name}!</h2>
            <p>Age: {age}</p>
        </div>
    );
}

function App() {
    return (
        <div>
            <Greeting name="Alice" age={25} />
            <Greeting name="Bob" age={30} />
        </div>
    );
}

Practice

1
Exercise

Create a React component that displays a user name.

Answer
function UserName({ name }) {
    return <h2>{name}</h2>;
}

Quick Quiz

1

Are props mutable in React?

Props are read-only. Components cannot modify their own props.

Interview Questions

Props are passed from parent to child and are read-only. State is managed within a component and can be updated.