管理员休息 CustomApp 抛出错误

admin on rest CustomApp throwing error

我们正在尝试在现有应用程序中包含 AOR(版本 1.3.1)。当我们遵循 documentation 时,我们遇到了一个错误。

List.js:442 Uncaught TypeError: Cannot read property 'list' of undefined
at Function.mapStateToProps [as mapToProps] (List.js:442)

我们还观察到最近版本中的文档和代码都发生了一些变化,无法解决问题。

如果我们使用 AOR(版本 1.2.3)那么它就可以工作。但是在代码中我们有以下不同 while combiningReducers

// create a Redux app
const reducer = combineReducers({
  admin: adminReducer([{name: 'CampaignDetails'}]),  
  locale: localeReducer(),
  form: formReducer,
  routing: routerReducer,
});

App.js 的代码主要取自文档:

import React from 'react';
import PropTypes from 'prop-types';
import { render } from 'react-dom';


// redux, react-router, redux-form, saga, and material-ui
// form the 'kernel' on which admin-on-rest runs
import { combineReducers, createStore, compose, applyMiddleware } from 'redux'
import { Provider } from 'react-redux'
import createHistory from 'history/createHashHistory'
import { Switch, Route } from 'react-router-dom'
import { ConnectedRouter, routerReducer, routerMiddleware } from 'react-router-redux';
import { reducer as formReducer } from 'redux-form';
import createSagaMiddleware from 'redux-saga';
import MuiThemeProvider from 'material-ui/styles/MuiThemeProvider';


// prebuilt admin-on-rest features
import {
  adminReducer,
  localeReducer,
  crudSaga,
  TranslationProvider
} from 'admin-on-rest';

import restClient from './restClient';
import GenericList from './alteui/components/genricComponents/GenricList';

// Customer
import CustomerEdit from './alteui/views/customer/customerEdit';

// your app labels
import messages from './i18n';


// create a Redux app
const reducer = combineReducers({
  admin: adminReducer,  
  locale: localeReducer(),
  form: formReducer,
  routing: routerReducer,
});
const sagaMiddleware = createSagaMiddleware();
const history = createHistory();

const store = createStore(reducer, undefined, compose(
  applyMiddleware(sagaMiddleware, routerMiddleware(history)),
  window.devToolsExtension ? window.devToolsExtension() : f => f,
));

sagaMiddleware.run(crudSaga(restClient));

const App = () => (
  <Provider store={store}>
    <TranslationProvider messages={messages}>
      <ConnectedRouter history={history}>
        <MuiThemeProvider>
          <Switch>
            <Route exact path="/"
              hasCreate render={
                (routeProps) => <GenericList resource="CampaignDetails" {...routeProps} />
              } />
          </Switch>
        </MuiThemeProvider> 
      </ConnectedRouter>
    </TranslationProvider>
  </Provider>
);

export default App

是的,我们对此感到抱歉。当前文档尚未与最新版本同步。在我们更新之前,请参阅此问题以获取更多信息:

https://github.com/marmelab/admin-on-rest/issues/1078

编辑

根据您的错误消息,我假设您正在读取自定义组件中某处的状态?

在这种情况下,我们不幸地在 1.3.0 版本中包含了一个 BC:状态已经重组。您可以在 issue

中找到更多信息

简而言之,使用 state.admin.resources[resource]

而不是 state.admin[resource]