First i do like to apologize if it’s a noob mistake. I’m trying to do a login page but i keep encountering this error. How can i fix this? Thank you all!
JavaScript
x
40
40
1
import React, { useState } from 'react';
2
import styled from 'styled-components';
3
import logo from '../assets/logo.png';
4
5
function initialState() {
6
return { user: '', password: '' };
7
}
8
9
10
const LoginPage = () => {
11
12
const [values, setValues] = useState();
13
14
function onChange(event) {`enter code here`
15
const { value, name } = event.target;
16
17
setValues({
18
values,
19
[name]: value
20
});
21
}
22
23
return (
24
<LoginCard>
25
<LoginLogoWrapper>
26
<img src={ logo } alt="logo"/>
27
</LoginLogoWrapper>
28
<Form>
29
<p>Acesse sua conta</p>
30
<input type="email" name="user" placeholder="E-mail" onChange={onChange} value={values.user}/>
31
<input type="password" name="password" placeholder="Senha" onChange={onChange} value={values.password}/>
32
<button>Entrar</button>
33
</Form>
34
</LoginCard>
35
);
36
};
37
38
39
export default LoginPage;
40
As requested i have put the code in the question, i’m sorry i’m new to stack overflow and coding in general. I already tried putting the function initializing the values inside the constant but it just throws another error.
Advertisement
Answer
As I saw at first from your screenshot, that the useState({…}) don’t have appropriate properties. Try like this:
JavaScript
1
5
1
const [values, setValues] = useState({
2
user: "",
3
password: ""
4
})
5
For more details check out this article.