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.
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.
function Greeting({ name, age }) { return ( <div> <h2>Hello, {name}!</h2> <p>Age: {age}</p> </div> ); } <Greeting name="John" age={25} />
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> ); }
Create a React component that displays a user name.
function UserName({ name }) {
return <h2>{name}</h2>;
}
Are props mutable in React?
Props are read-only. Components cannot modify their own props.
Props are passed from parent to child and are read-only. State is managed within a component and can be updated.