1 min read

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.

Get the React Practice Calendar!

28 days of focused practice of increasing difficulty, going through everything from Fundamentals, Data fetching, Forms and using Intervals in React.

You will also get notified whenever a new challenge is published.