threepointone / glamor

inline css for react et al
MIT License
3.66k stars 199 forks source link

Changing themes dynamically gets stuck after two changes #364

Closed nareshbhatia closed 6 years ago

nareshbhatia commented 6 years ago

In my app, I am trying to provide the ability to change themes dynamically. I have two themes - light and dark.

@observer
class App extends Component {
    render() {
        const { paletteType } = rootStore.appStore;
        const palette = {
            primary: {
                main: blue[500]
            },
            secondary: {
                main: pink.A400
            },
            error: {
                main: red.A400
            },
            type: paletteType,
            // Initialize background to white (default is #fafafa)
            // This allows pictures with white background to blend in.
            background: {
                default: paletteType === 'light' ? '#ffffff' : '#303030'
            }
        };
        const theme = createMuiTheme({ palette });

        css.global('body', {
            height: '100%',
            margin: 0,
            background: theme.palette.background.default,
            fontFamily: theme.typography.fontFamily,
            fontSize: theme.typography.fontSize,
            color: theme.palette.text.primary,

            // Helps fonts on OSX look more consistent with other systems
            WebkitFontSmoothing: 'antialiased',
            MozOsxFontSmoothing: 'grayscale',

            // Use momentum-based scrolling on iOS devices
            WebkitOverflowScrolling: 'touch'
        });

        return (
            <ThemeProvider theme={theme}>
                <Provider rootStore={rootStore}>
                    <Shell />
                </Provider>
            </ThemeProvider>
        );
    }
}

export default App;

What am I missing?

You can see the full working code here: https://github.com/nareshbhatia/mobx-shop-glamorous

nareshbhatia commented 6 years ago

Found a solution - thanks to @tikotzky. See https://github.com/paypal/glamorous/issues/401