I want to send user to backend in function handleJoin().
After setUser is called, the initial data not changed.
How to fix it without using class
App.js
import React, { useState } from "react";
import Join from "./components/Join";
const App = () => {
const [user, setUser] = useState({ });
// Send user data to backend
const handleJoin = (input) => {
console.log(input); // > {name: "myname"}
setUser(input); // Not working!
console.log(user); // > { }
// I want to connect backend here
// But the user objet is empty
};
return <Join onJoin={handleJoin} />;
};
export default App;
Joincomponent does, and in particular how itsonJoinprop is used?