It is necessary for me at a choice chekboksom that the Page2 component was drawn. I created a useState where I keep track of the value of the checkbox, but I don’t know how to navigate programmatically when the checkbox is selected. How can i do this?
export default function Home() {
const [checked, setChecked] = useState(false);
const navigate = useNavigate();
const handleChange = () => {
setChecked(!checked);
};
return (
<>
<input type="checkbox" onChange={handleChange}></input>
</>
);
}
>Solution :
const handleChange = () => {
setChecked(!checked);
if (!checked) {
navigate('/')
}
};