上下文:我们开始迁移Backbone.js应用,并在主干和React之间创建了一种屏障视图。
Backbone视图的相关部分如下:
int main(int argc, char **argv) {
printf("The first 3 letters of the first argument is:\n");
int i = 0;
while (i < 3) {
printf("%d = %c\n", .... I don't know what to put here);
i++;
}
printf("The full word was: %s\n\n", I don't know what to put here);
printf("The first 3 letters of the second argument is:\n");
int j = 0;
while (j < 3) {
printf("%d = %c\n", j, .... I don't know what to put here);
j++;
}
printf("The full word was: %s\n", I don't know what to put here);
}
我尝试连接的React组件如下所示:
{
...
render: function() {
const component = React.createElement(this.component, this.getComponentProps());
const rootComponent = React.createElement(Provider, { store }, component);
this.reactComponent = ReactDOM.render(rootComponent, this.el);
...
},
...
}
然后,在我定义的define(function(require) {
const React = require('react');
const { connect } = require('react-redux');
class SomeConnectedComponent extends React.Component {
constructor(props) {
super(props)
}
render() {
return (
<div>
<span>hello world</span>
<pre>{JSON.stringify(this.props, null, 2)}</pre>
</div>
);
}
}
const mapStateToProps = (state, ownProps) => ({});
const mapDispatchToProps = dispatch => ({});
return connect(mapStateToProps, mapDispatchToProps)(SomeConnectedComponent);
});
中将SomeConnectedComponent
作为this.component
传递。 RView
中的元素创建将RView
包装在this.component
中,因此它是直接后代。当我请勿使用<Provider>
时,在React DevTools中确认正确的组件层次结构。问题是,当使用connect
并加载页面时,出现以下错误:
connect
我尝试在没有react-redux.js:1119 Uncaught Error: Could not find "store" in either the context or props of "Connect(SomeConnectedComponent)". Either wrap the root component in a <Provider>, or explicitly pass "store" as a prop to "Connect(SomeConnectedComponent)".
at invariant$2 (react-redux.js:1119)
at new Connect (react-redux.js:1320)
at react-dom.js:4698
at measureLifeCyclePerf (react-dom.js:4479)
at ReactCompositeComponentWrapper._constructComponentWithoutOwner (react-dom.js:4697)
at ReactCompositeComponentWrapper._constructComponent (react-dom.js:4688)
at ReactCompositeComponentWrapper.mountComponent (react-dom.js:4591)
at Object.mountComponent (react-dom.js:11409)
at ReactCompositeComponentWrapper.performInitialMount (react-dom.js:4774)
at ReactCompositeComponentWrapper.mountComponent (react-dom.js:4661)
的情况下加载页面(效果很好),并使用React DevTools能够确认connect()
组件已通过<Provider>
道具,并且正确填入了我的store
。该商店也可以正确显示在Redux DevTools中,因此可以确定它已经创建。
我对自己做错的事情很茫然。