17. Refs in React
Activity 17.01: Creating a Form with an Autofocus Input Element
Solution:
- Create a new React app using the create-react-app CLI:
$ npx create-react-app autofocus-form
- Move into the new React applications folder and start the
create-react-app
development server:$ cd autofocus-form/ && npm start
- Inside the
App.js
file, change theApp
component to only return a plainform
component:import React from "react"; class App extends React.Component { render() { return <form />; } } export default App;
- Inside the
form
component, add three input fields – one forfirstname
, one forlastname
, and a third one foremail
:class App extends React.Component { render() { return ( <form> <input type="text" placeholder="firstname" />...