import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; import { faCaretDown } from "@fortawesome/free-solid-svg-icons"; import { useRef, useState } from "react"; import { useClickAway } from "react-use"; import router, { useRouter } from "next/router"; import FLAGS from "components/langs"; import classNames from "classnames"; export const SelectLanguages = () => { const { locale } = useRouter(); const ref = useRef(null); const [open, setOpen] = useState(false); useClickAway(ref, () => setOpen(false)); const country = FLAGS.find((flag) => flag.code === locale) ?? FLAGS[0]; const SelectedCountry = country?.icon || (() => null); return (
setOpen(!open)} > {country.name}
{FLAGS.map((lang) => { const Component = lang.icon; return (
{ // change locale of the app router.push(router.asPath, router.asPath, { locale: lang.code, }); setOpen(false); }} > {lang.name}
); })}
); };