React-Native Redux存储根组件错误:'查找类组件,获取对象对象'

时间:2017-04-27 13:09:46

标签: reactjs react-native react-redux react-native-router-flux

这有效:

const Router = connect()(Router);

// --- your exported main router
export default class MyExportedRouter extends React.Component {
    constructor(props) {
        super(props);
    };

    render() {
        return (
            <Provider store={store}>
                <Router scenes={scenes} />
            </Provider>
        );
    }
}

但如果我改变

const Router = connect()(Router);
...
<Router scenes={scenes} />
...

const myConnectedRouter = connect()(Router);
...
<myConnectedRouter scenes={scenes} />
...

失败并出现以下错误:

  

寻找一个类组件,获取一个对象对象

我的完整代码在这里: https://github.com/aksonov/react-native-router-flux/blob/master/docs/REDUX_FLUX.md

1 个答案:

答案 0 :(得分:0)

myConnectedRouter应该大写,如MyConnectedRouter

connect()返回'更高阶React组件类'(https://github.com/reactjs/react-redux/blob/master/docs/api.md#connectmapstatetoprops-mapdispatchtoprops-mergeprops-options

React组件必须大写(https://facebook.github.io/react/docs/jsx-in-depth.html#html-tags-vs.-react-components

此问题已在ReactJS的上下文中解决:https://stackoverflow.com/a/30373505/1905712