在 react-redux 中连接时出错

Error with connect in react-redux?

本文关键字:出错 连接 react-redux      更新时间:2023-09-26

我在我的 react-native/redux 应用程序中收到此错误,尽管我相信我已经将根组件包装在<Provider>中:

"在'连接(FirstView)'的上下文或道具中都找不到'商店'。要么将根组件包装在<Provider>中,要么显式地将'store'作为道具传递给Connect(PropertyView)。

我正在将根组件包装在容器/根中的提供程序中.js:

class Root extends React.Component {
    render() {
        return (
            <Provider store={store}>
                {() => <SearchPage />}
            </Provider>
        );
    }
}
export default Root;

然后 SearchPage 通过 NavigatorIOS 转换为 SearchResults,SearchResults 通过 NavigatorIOS 转换为 PropertyView:

this.props.navigator.push({
        title: "Property",
        component: PropertyView,
        passProps: {property: property,
                    addToSaved: addToSaved
                    }
    });

我无法弄清楚我还缺少什么导致此错误。任何建议将不胜感激!

您正在创建一个连接的组件?

// SearchPage.js
import { connect } from 'redux'
const SearchPage = React.createClass({
...
})
export default connect()(SearchPage)

这只是要尝试的东西...希望对您有所帮助。