I´m trying to update a state inside this:
const [username, setUsername] = useState("");
const [room, setRoom] = useState("");
const [connected, setConnected] = useState(false);
const navigate = useNavigate();
const handleClick = (e) => {
e.preventDefault();
setConnected(true);
console.log(connected);
navigate("/chatroom", {
state: { username, room, connected },
});
};
<button
type="submit"
className="btn"
onClick={(e) => {
handleClick(e);
}}
>
The problem is that the state is not updating when I click. I know is an async problem, but I´ve tried the other options asked in SO but I dont get it.