Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

add language switcher to react-admin

import * as React from 'react';
import { forwardRef, memo } from 'react';
import { ReactQueryDevtools } from 'react-query/devtools';
import {
    AppBar,
    Layout,
    Logout,
    UserMenu,
    useLocaleState,
    useUserMenu,
} from 'react-admin';
import { MenuItem, MenuItemProps, ListItemIcon } from '@mui/material';
import Language from '@mui/icons-material/Language';

const SwitchLanguage = forwardRef(
    (props, ref) => {
        const [locale, setLocale] = useLocaleState();
        const { onClose } = useUserMenu();

        return (
            <MenuItem
                ref={ref}
                {...props}
                sx={{ color: 'text.secondary' }}
                onClick={event => {
                    setLocale(locale === 'en' ? 'fr' : 'en');
                    onClose();
                }}
            >
                <ListItemIcon sx={{ minWidth: 5 }}>
                    <Language />
                </ListItemIcon>
                Switch Language
            </MenuItem>
        );
    }
);

const MyUserMenu = () => (
    <UserMenu>
        <SwitchLanguage />
        <Logout />
    </UserMenu>
);

const MyAppBar = memo(props => <AppBar {...props} userMenu={<MyUserMenu />} />);

export default props => (
    <>
        <Layout {...props} appBar={MyAppBar} />
        <ReactQueryDevtools
            initialIsOpen={false}
            toggleButtonProps={{ style: { width: 20, height: 30 } }}
        />
    </>
);
Comment

PREVIOUS NEXT
Code Example
Javascript :: send confirmation email strapi 
Javascript :: sumar un mes a una fecha javascript moment 
Javascript :: monaco editor no numbers 
Javascript :: JavaScript Code to Perform GCD using Recursion 
Javascript :: how to add a message sound in angular 
Javascript :: pass ref to class component react 
Javascript :: switch variables javascript 
Javascript :: how to send csrf middleware token in django ajax 
Javascript :: .reduce javascript 
Javascript :: react component key prop 
Javascript :: how to convert string to toggle case in javascript 
Javascript :: url fetch app pass payload and headers 
Javascript :: react-datepicker float position 
Javascript :: jquery check component exists 
Javascript :: async function javascript dec 
Javascript :: javascript scroll to element with offset 
Javascript :: LocomotiveScroll npm 
Javascript :: javascript sig figs 
Javascript :: jquery generate post entire page 
Javascript :: random email js 
Javascript :: scrape html table javascript 
Javascript :: regex 1-31 days 
Javascript :: JsonArrayAttribute can also be added to the type to force it to deserialize from a JSON array. 
Javascript :: JavaScript: Updating Object Properties 
Javascript :: javascript injection in mongodb 
Javascript :: how to remove only green background from video using ffmeg nodejs 
Javascript :: jquery get element by data attribute 
Javascript :: javascript set elements width by tag name 
Javascript :: callback hell 
Javascript :: back press subscriptions i is not a function react native 
ADD CONTENT
Topic
Content
Source link
Name
5+6 =