Created
May 13, 2019 12:23
-
-
Save goldylucks/d8d8b1d6c1f36d4867ba462f129121a9 to your computer and use it in GitHub Desktop.
Answer to user's question
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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} | |
/> | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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