Last active
March 3, 2022 22:45
-
-
Save LucasCalazans/f66a6789648bd5d2e8e1a97468ba1a28 to your computer and use it in GitHub Desktop.
Form validation using useMemo
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
const CreateAccountForm = () => { | |
const [password, setPassword] = useState(''); | |
const [showErrors, setShowErrors] = useState(false); | |
const checkPassword = event => { | |
const { value } = event.target; | |
setShowErrors(value.length < 8); | |
setPassword(value); | |
} | |
const memoizedErrors = useMemo(() => <Errors active={showErrors} />, [showErrors]); | |
return ( | |
<form> | |
<h1>Login</h1> | |
<input placeholder="Email" /> | |
<input type="password" placeholder="Password" value={password} onChange={checkPassword} /> | |
{memoizedErrors} | |
</form> | |
); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment