迁移到MaterialUI V4

时间:2019-09-13 11:21:10

标签: javascript reactjs material-ui

当我分别将materialUI / core和materialUI / icons从3.9.3升级到4.4.1以及从3.0.2升级到4.4.1时。

我遇到了错误

TypeError:styles_1.createGenerateClassName不是函数

我正在从@ material-ui / core / styles导入createMuiTheme。 我要如何解决这个问题?任何人都可以对此提出一些建议。请帮我。谢谢

23:59:59

这是我的muiTheme.js文件

import React, { Suspense, lazy } from 'react';
import { createStore, compose, applyMiddleware } from 'redux';
import { Provider } from 'react-redux';
import { createBrowserHistory } from 'history';
import { routerMiddleware } from 'connected-react-router';
import createSagaMiddleware from 'redux-saga';
import { MuiThemeProvider } from '@material-ui/core/styles';
import analyticsMiddleware from './module/analytics/middleware';
import 'react-block-ui/style.css';
import muiTheme from './muiTheme';
import initialState from './store/initialState';
import rootReducer from './reducer';
import rootSaga from './saga';
import ErrorBoundary from './module/common/components/ErrorHandler';

const sagaMiddleware = createSagaMiddleware();
const history = createBrowserHistory();
const store = createStore(
  rootReducer,
  initialState,
  compose(
    applyMiddleware(sagaMiddleware, routerMiddleware(history), analyticsMiddleware),
    window.devToolsExtension ? window.devToolsExtension() : f => f
  )
);

sagaMiddleware.run(rootSaga);

const theme = muiTheme;

const App = () => (
    <ErrorBoundary>
      <Provider store={store}>
          <MuiThemeProvider theme={theme}>
              <div>
                <Suspense fallback={<div>Loading...</div>}>

                </Suspense>
              </div>
          </MuiThemeProvider>
      </Provider>
    </ErrorBoundary>
);

export default App;

1 个答案:

答案 0 :(得分:0)

尝试将以下代码行添加到引发错误的文件中:

import createGenerateClassName from 'material-ui/core/styles/createGenerateClassName