I'm new to React, I'm trying to develop a realtime application with node js but at some point I'm stuck and can't progress. Under normal circumstances, I would write the User companet as a class, but when I did not have enough knowledge, I turned to the function. I leave the error below. Thank you. app.js
import React, {useState, useEffect} from "react";
import User from './Companents/User'
function App() {
const [LogIn, SetLogIn] = useState(false),
[Username, SetUsername] = useState(''),
[Password, SetPassword] = useState(''),
[Response, SetResponse] = useState('')
const HandleSubmit = async function (e) {
e.preventDefault()
SetResponse( User(Username, Password) )
}
return (
<div className={(!LogIn) ? 'App LogInScreen' : 'App'}>
{!LogIn ? (
<div className="LogInArea">
<h3>Log In</h3>
{Response}
<form className="LogInInputs" onSubmit={HandleSubmit}>
<input type="text" placeholder="Username" onChange={(e) => SetUsername(e.target.value)}/>
<input type="password" placeholder="Password" onChange={(e) => SetPassword(e.target.value)}/>
<button type="submit">Submit</button>
</form>
<p>Do you not have a account? <a href="">Let's create</a></p>
</div>
) : (
<div> Welcome User.Name</div>
)}
</div>
);
}
export default App;
user.js
import React, {useState, useEffect} from "react";
import axios from "axios";
function Login(username, password) {
const [Res,setRes] = React.useState(0)
axios.post('http://localhost:8080/login', {
'username': username,
'password': password
}).then(function (response) {
// SetRes(response.data)
console.log(response.data.code)
// setRes(1)
})
return 1;
}
export default Login