creating a dynamic icon with navigation for the header of my application I come across this 'delay', that is, it is always a click late, it even navigates etc but it needs several clicks to work, to better exemplify I will post a gif
the icons are used to navigate between the Home and Editor pages of my app, so using useNavigate
import { useState } from "react";
import { AiOutlineHome, AiOutlineAppstoreAdd } from "react-icons/ai";
import { useNavigate } from "react-router-dom";
import "./style.scss";
export default function Header() {
const navigate = useNavigate();
const HomePage = <AiOutlineHome />;
const EditorPage = <AiOutlineAppstoreAdd />;
const [home, setHome] = useState(HomePage);
const handleClick = () => {
if (home === HomePage) {
setHome(EditorPage);
navigate("/");
} else {
setHome(HomePage);
navigate("/editor");
}
};
return (
<>
<div className="home">
<span onClick={handleClick}>{home}</span>
</div>
</>
);
}
