Listing 8-3: Updating an input element with one-way data flow
Your email address:
import {useState} from 'react';
function SignUp(props){
const [emailAddress,setEmailAddress] = useState('');
const handleChange = (e)=>{
setEmailAddress(e.target.value);
}
return(
<>
<form>
<label>Enter your email address:
<input value={emailAddress} onChange={handleChange} type="text" />
</label>
</form><br />
Your email address: {emailAddress}
</>
)
}
export default SignUp;
Download the examples, report issues, and ask/answer questions in the discussion area by visiting the book's github page. All of the code for the book is also available on codesandbox.io for you to play around with.
ReactJS Foundations is published by John Wiley and Sons, Inc and is available in paperback and eBook.