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" />...