docs_headless/src/content/docs/useLocaleState.md
The useLocaleState hook allows to read and update the locale. It uses a syntax similar to react's useState hook.
const [locale, setLocale] = useLocaleState();
useLocaleState is generally used in components allowing the user to switch the interface language:
import * as React from "react";
import { useLocaleState } from 'ra-core';
const LocaleSwitcher = () => {
const [locale, setLocale] = useLocaleState();
return (
<div>
<div>Language</div>
<button
disabled={locale === 'fr'}
onClick={() => setLocale('fr')}
>
English
</button>
<button
disabled={locale === 'en'}
onClick={() => setLocale('en')}
>
French
</button>
</div>
);
};
export default LocaleSwitcher;