Skip to content

Instantly share code, notes, and snippets.

@goldylucks
Created May 13, 2019 12:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save goldylucks/d8d8b1d6c1f36d4867ba462f129121a9 to your computer and use it in GitHub Desktop.
Save goldylucks/d8d8b1d6c1f36d4867ba462f129121a9 to your computer and use it in GitHub Desktop.
Answer to user's question
class SignUpForm extends React.Component {
// other stuff
render()
const shouldMarkError = (field) => {
const hasError = errors[field];
const shouldShow = this.state.touched[field];
return hasError ? shouldShow : false;
};
// ...
<input
className={shouldMarkError('email') ? "error" : ""}
onBlur={this.handleBlur('email')}
type="text"
placeholder="Enter email"
value={this.state.email}
onChange={this.handleEmailChange}
/>
}
}
class SignUpForm extends React.Component {
// other stuff
shouldMarkError(field){
const hasError = errors[field];
const shouldShow = this.state.touched[field];
return hasError ? shouldShow : false;
};
render()
// ...
<input
className={this.shouldMarkError('email') ? "error" : ""}
onBlur={this.handleBlur('email')}
type="text"
placeholder="Enter email"
value={this.state.email}
onChange={this.handleEmailChange}
/>
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment