// Modules import { Link, useLocation } from "react-router-dom"; import { v4 as uuidv4 } from "uuid"; import { motion } from "framer-motion"; import { useDispatch, useSelector } from "react-redux"; import { useEffect, useState } from "react"; // Types import { RootState } from "../../types/store.types"; import { ICategoriesData } from "../../types/data.types"; // Actions import { setActiveLink } from "../../actions/setActiveLink.action"; // Animations import { linkMotion } from "../../animations/subNav.animations"; // Api import { Api } from "../../api/Api"; import { url } from "../../url"; // Components import Loader from "../global/Loader"; const SubNav = () => { const activeLink = useSelector( (state) => state.activeLink.active ); const language = useSelector( (state) => state.language.title ); const dispatch = useDispatch(); const onClickLink = (active: number) => { dispatch(setActiveLink(active)); }; const [data, setData] = useState(); // Api const api = new Api(url + "/categories"); useEffect(() => { api.get(data, setData); }, [language]); const location = useLocation(); useEffect(() => { if (!location.pathname.includes("category")) return; const category = location.pathname[location.pathname.length - 1]; onClickLink(parseInt(category)); }, [location]); return ( ); }; export default SubNav;