Recall & Review
beginner
What are default props in React?
Default props are values given to a React component's props that are used if no value is provided by the parent component. They help ensure the component works with sensible defaults.
Click to reveal answer
beginner
How do you set default props in a React functional component?
You can set default props by assigning default values in the function parameter list, like <code>function MyComponent({ title = 'Hello' }) { ... }</code>. This way, if <code>title</code> is not passed, it defaults to 'Hello'.Click to reveal answer
beginner
Why are default props useful in React components?
They prevent errors by providing fallback values, improve component reusability, and make components easier to use without always specifying every prop.
Click to reveal answer
beginner
Can you override default props in React? How?
Yes, you override default props by passing a prop value when using the component. The passed value replaces the default.
Click to reveal answer
beginner
Show an example of a React functional component with default props using ES6 syntax.
Example:<br><pre>function Greeting({ name = 'Friend' }) {<br> return <h1>Hello, {name}!</h1><br>}</pre>Click to reveal answer
What happens if you don't pass a prop that has a default value in a React component?
✗ Incorrect
If a prop is not passed, React uses the default value defined for that prop.
How do you define default props in a React functional component?
✗ Incorrect
In functional components, default props are set by giving default values in the parameter list.
Can default props be overridden by passing a prop value?
✗ Incorrect
Props passed to a component override any default props set.
Which of these is a benefit of using default props?
✗ Incorrect
Default props provide fallback values, preventing errors if props are missing.
What is the default prop value for
name in this component?<br>function Welcome({ name = 'Guest' }) { return <p>Hi, {name}!</p> }✗ Incorrect
The default value for
name is set to 'Guest' in the function parameter.Explain what default props are in React and why they are useful.
Think about what happens when a prop is missing.
You got /4 concepts.
Describe how to set default props in a React functional component with an example.
Use ES6 syntax for function parameters.
You got /3 concepts.