I'm using useNavigate
to go to the component and need to pass data (state) to this ChatRoom
component when I click a button.
The component is on the route /chatroom
. I'm using React Router Dom v6
. I have read the documentation but cannot find what I'm looking for.
export default function Home() {
const [username, setUsername] = useState("");
const [room, setRoom] = useState("");
const navigate = useNavigate();
const handleClick = () => {
navigate("/chatroom");
};
return (
<button
type="submit"
className="btn"
onClick={() => {
handleClick();
}}
>
Join Chat
</button>
);
}