Skip to content

Instantly share code, notes, and snippets.

@thiagoadsix
Last active October 24, 2020 23:39
Show Gist options
  • Save thiagoadsix/f34911ed6f2c02feb3f8825101d61c78 to your computer and use it in GitHub Desktop.
Save thiagoadsix/f34911ed6f2c02feb3f8825101d61c78 to your computer and use it in GitHub Desktop.
{
"env": {
"browser": true,
"es6": true
},
"extends": [
"plugin:react/recommended",
"airbnb",
"plugin:@typescript-eslint/recommended",
"prettier/@typescript-eslint",
"plugin:prettier/recommended"
],
"globals": {
"Atomics": "readonly",
"SharedArrayBuffer": "readonly"
},
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaFeatures": {
"jsx": true
},
"ecmaVersion": 2018,
"sourceType": "module"
},
"plugins": [
"react",
"@typescript-eslint",
"react-hooks",
"prettier"
],
"rules": {
"no-unused-expressions": "off",
"@typescript-eslint/no-unused-expressions": "off",
"react-hooks/rules-of-hooks": "error",
"react/jsx-props-no-spreading": "off",
"react/prop-types": "off",
"react-hooks/exhaustive-deps": "warn",
"react/jsx-filename-extension": [
1,
{
"extensions": [
".tsx"
]
}
],
"import/prefer-default-export": "off",
"import/extensions": [
"error",
"ignorePackages",
{
"ts": "never",
"tsx": "never"
}
],
"no-use-before-define": "off",
"prettier/prettier": "error"
},
"settings": {
"import/resolver": {
"typescript": {}
}
}
}
import React, { useCallback, useRef } from 'react';
import { FiArrowLeft, FiMail, FiLock, FiUser } from 'react-icons/fi';
import { FormHandles } from '@unform/core';
import { Form } from '@unform/web';
import * as Yup from 'yup';
import logo from '../../assets/logo.svg';
import Input from '../../components/Input/index';
import Button from '../../components/Button/index';
import { Container, Content, Background } from './styles';
const SignUp: React.FC = () => {
const formRef = useRef<FormHandles>(null);
console.log(formRef);
const handleSubmit = useCallback(async (data: object) => {
try {
const schema = Yup.object().shape({
name: Yup.string().required('Nome obrigatório'),
email: Yup.string()
.required('E-mail obrigatório')
.email('Digite um e-mail válido'),
password: Yup.string().min(6, 'No mínimo 6 digitos'),
});
await schema.validate(data, {
abortEarly: false,
});
} catch (error) {
// como está no log, o erro está sendo aqui
formRef.current?.setErrors({
name: 'Nome obrigatório',
});
}
}, []);
return (
<Container>
<Background />
<Content>
<img src={logo} alt="GoBarber" />
<Form ref={formRef} onSubmit={handleSubmit}>
<h1>Faça seu cadastro</h1>
<Input type="text" icon={FiUser} name="name" placeholder="Nome" />
<Input type="text" icon={FiMail} name="email" placeholder="E-mail" />
<Input
type="password"
icon={FiLock}
name="password"
placeholder="Senha"
/>
<Button type="submit">Cadastrar</Button>
</Form>
<a href="create-count">
<FiArrowLeft />
Voltar para login
</a>
</Content>
</Container>
);
};
export default SignUp;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment