我正在尝试使用react
+ redux
+ react-redux
+react-router
理念将我的组件连接到商店。即使父级用商店封装,我也会收到此错误:
[Invariant Violation: Could not find "store" in either the context or props of "Connect(Body)".
Either wrap the root component in a <Provider>, or explicitly pass "store" as a prop to "Connect(Body)".]
name: 'Invariant Violation', framesToPop: 1 }
代码(为简洁起见缩短了导入)
组件/Table.jsx
export default class Table extends React.Component {
constructor(props) {
super(props);
}
render() {
return (
{this.props.barcodes.map(barcode =>
<p key={barcode.value}>
)}
</tbody>
</table>
);
}
}
容器/BarcodeListing.jsx
import Table from 'components/Table'
import { connect } from 'react-redux'
function mapStateToProps(state) {
return { barcodes: state.barcodes };
}
@connect(mapStateToProps)
class Body extends React.Component {
render() {
return (
<Table barcodes={barcodes}/>
);
}
}
export default class extends React.Component {
render() {
return (
<Container>
<Body />
</Container>
);
}
}
路线.jsx
import BarcodeListing from 'containers/barcodeListing';
const reducer = combineReducers(Object.assign({}, reducers, {
routing: routeReducer
}));
const finalCreateStore = compose(window.devToolsExtension())(createStore);
const store = finalCreateStore(reducer, {});
return (
<Provider store={store}>
<Router history={BrowserHistory} onUpdate={onUpdate}>
<Route path='/' component={BarcodeListing} />
</Router>
</Provider>
);
};
包.json
"react": "shripadk/react-ssr-temp-fix",
"react-dom": "^0.14.6",
"react-hot-loader": "^1.2.7",
"react-redux": "^4.0.6",
"react-router": "^1.0.0-beta3",
"react-style": "^0.5.5",
"redux": "^3.0.6",
"redux-logger": "^2.3.2",
"redux-simple-router": "^1.0.2",