I have a React
component that has a form for submitting user information.
The main issue I'm facing is setting a default value in the input field. When the page loads, I want the input field to display the user's existing email address by default and update only if the user decides to input a new email address.
I understand that you can't use both onChange
and value
on the same <input>
field. So, what approach should I take to achieve this functionality?
<input
type="email"
name="email"
id="email-field"
onChange={handleChange}
value={emailAddress}
/>
export default {
props: { defaultEmail: String },
data() {
return {
emailAddress: this.defaultEmail || ''
};
}
}