Practice React Context by building a TextField component using composition
Build a TextField
component that allows users to add a Label
and Input
to a form:
<TextField>
<Label>First name</Label>
<Input />
</TextField>
The component should link the Label
and the Input
by generating a unique id with the useId React hook and adding the HTML for
attribute to the label.
Here is the sample HTML output:
<div>
<label htmlFor="name">First name</label>
<input id="name" type="text" />
</div>
Use React Context to build your solution.
💡
Ready to check your work?
Become a member and get access to the official solution and the comments section for feedback and discussion.
Become a member and get access to the official solution and the comments section for feedback and discussion.
Member discussion