Material-UI - Support babel-plugin-react-css-modules and rtl app

503 views Asked by At

material-ui: v4.8.2
react: v16.12.0

babel-plugin-react-css-modules with rtl app - I thought to use injectFirst but then I get a warning: Material-UI: you cannot use the jss and injectFirst props at the same time.

My guess is that I should define differently the jss so it would support rtl and css modules.

// Configure JSS - How should I add here the css-modules styles?
const jss = create({ plugins: [...jssPreset().plugins, rtl()] }); 

For rtl I should do:

// Configure JSS
const jss = create({ plugins: [...jssPreset().plugins, rtl()] });

<StylesProvider jss={jss}>
            <ThemeProvider theme={theme}>
                <AppContainer />
            </ThemeProvider>);
        </StylesProvider>

for css-modules styles I should do:

<StylesProvider injectFirst>
            <ThemeProvider theme={theme}>
                <AppContainer />
            </ThemeProvider>);
        </StylesProvider>

Can anyone please advise how I should combine both?

1

There are 1 answers

0
chenop On BEST ANSWER

Finally solved it.

Do the following:

Add jss-insertion-point just below the <head>

<head>
     <!-- jss-insertion-point -->
     ...
</head>

Root.js:

    import rtl from 'jss-rtl';
    import { StylesProvider, jssPreset } from '@material-ui/core/styles';

    let jss = create({
      plugins: [...jssPreset().plugins, rtl()],
      insertionPoint: 'jss-insertion-point',
    });

    const Root = () => (
       <Provider store={store}>
           <StylesProvider jss={jss}>
               <ThemeProvider theme={theme}>
                    <Router history={history} routes={routes}/>
               </ThemeProvider>);
           </StylesProvider>
       </Provider>
    );

export default Root;