I would like my Next.js app to remember which language the user prefers, therefore I want to store it in a cookie on client side. I have 2 language options: EN & FR.
By default the language is set up for English (no cookie, myapp.com/
), but once the user clicks on EN preference, the URL changes to myapp.com/en
and this selected language should be stored. The same applies for French.
const [language, setLanguage] = useState(false);
<Link
href={`/${router.locale === 'en' ? 'fr' : 'en'}`}
locale={false}
>
<a
onClick={() => {
setLanguage((language) => !language);
// setCookie({});
}}
>
{` ${language ? 'en' : 'fr'}`}
</a>
Where and how can I use the cookie or session storage so the backend can see it?