Last active
May 28, 2019 19:02
-
-
Save LucasCalazans/cb653a56a48f8e53c539807b7eca8c9b to your computer and use it in GitHub Desktop.
Form validation without useMemo
This file contains 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
const rules = [ | |
'8 characteres', | |
'lowercase word', | |
'uppercase word', | |
]; | |
// Lista de erros | |
const Errors = ({ active }) => { | |
return active && ( | |
<ul> | |
{rules.map((value, index) => ( | |
<li key={index}>{value}</li> | |
))} | |
</ul> | |
); | |
} | |
const CreateAccountForm = () => { | |
const [password, setPassword] = useState(''); | |
const [showErrors, setShowErrors] = useState(false); | |
const checkPassword = event => { | |
const { value } = event.target; | |
setShowErrors(value.length < 8); | |
setPassword(value); | |
}; | |
return ( | |
<form> | |
<h1>Login</h1> | |
<input placeholder="Email" /> | |
<input | |
type="password" | |
placeholder="Password" | |
value={password} | |
onChange={checkPassword} | |
/> | |
<Errors active={showErrors} /> | |
</form> | |
); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment