Pass every field of an object as a separate prop.
Acceptance criteria
- 1.#root should show Ada engineer.
React Tutorial · Components and Props
These 10 tasks go with the Spreading and Forwarding Props chapter. 5 of them ask you to build something small from scratch; 5 give you code that is already broken and ask you to work out why. Set aside about 90 minutes for the whole set, though you can do them in any order.
Nothing here is marked by a person. When you press Submit, the editor checks your code against the points listed under each task and tells you straight away what passed and what didn't (you need a free account to submit). If you get stuck, there are hints, and a worked solution once you've had a go. The first 2 tasks are free; the rest are part of the practice plan.
If it's been a while since you read the chapter, here is how it starts: “Spreading props lets a wrapper accept everything the underlying element accepts, without listing every attribute by hand.” .
1.Spread an object as propsexercise · easy · 10 min
Pass every field of an object as a separate prop.
Passes when: #root should show Ada engineer.
2.Collect the restexercise · easy · 10 min · practice plan
Take one prop by name and pass the rest to the element.
Passes when: #root should show Save.
3.Override after the spreadexercise · easy · 10 min · practice plan
Spread the defaults, then override one prop.
Passes when: #root should show override wins.
4.Forward a classNameexercise · medium · 10 min · practice plan
Let a caller add a class while keeping the component's own.
Passes when: div.card.wide should show styled.
5.Forward a handlerexercise · medium · 10 min · practice plan
Pass an onClick through to the underlying button.
Passes when: #msg should show clicked.
6.Fix the object passed wholebug fix · easy · 8 min
Passing the object as one prop is not the same as spreading it.
Passes when: #root should show Ada engineer.
7.Fix the spread in the wrong orderbug fix · easy · 8 min · practice plan
The spread comes last, so it overwrites the explicit prop.
Passes when: #root should show override wins.
8.Fix the rest props never forwardedbug fix · easy · 8 min · practice plan
The extra props are collected but never reach the element.
Passes when: The button should receive type=submit.
9.Fix the className that replaces instead of addingbug fix · medium · 8 min · practice plan
Forwarding a class should keep the component's own class too.
Passes when: The div should have both card and wide.
10.Fix the handler swallowed by the wrapperbug fix · medium · 8 min · practice plan
The wrapper defines its own onClick, so the forwarded one never runs.
Passes when: Clicking should show clicked.
Between them these tasks cover Spread, Rest props and Forwarding.
Looking for a different chapter? See every practice set, or switch to the interview theory questions.