我刚开始在我的反应站点上使用 redux。相当小。(我正在关注本教程https://medium.com/front-end-developers/handcrafting-an-isomorphic-redux-application-with-love-40ada4468af4#.mhkgga84t将一些代码插入到我的反应站点中案子)。但是当我正在进行并尝试访问this.props.store
它时,即使我<Provider store={store}>
在我的应用程序中也无法使用它。这是我的客户端和应用程序代码(我可以提供更多我只是不知道还要添加什么):
// src/client.js
import React from 'react';
import ReactDOM from 'react-dom';
import { Router } from 'react-router';
import { routes } from './routes';
import { browserHistory } from 'react-router'
import { createStore, combineReducers } from 'redux';
import { Provider } from 'react-redux';
import * as reducers from './reducers';
import { fromJS } from 'immutable';
let initialState = window.__INITIAL_STATE__;
Object.keys(initialState).forEach(key => {
initialState[key] = fromJS(initialState[key]);
});
const reducer = combineReducers(reducers);
const store = createStore(reducer, initialState);
console.log('store', store);
ReactDOM.render(<Provider store={store}><Router routes={routes} history={browserHistory} store={store} /></Provider>, document.getElementById('app'));
但我无法store
从this.props
. 它应该在这里可用吗?所以我const { todos, dispatch } = this.props;
最终能做到吗?
// src/components/app.js
import React from 'react';
import { Link } from 'react-router';
import HeaderComponent from './common/header';
import ShareFooterComponent from './common/share-footer';
import FooterComponent from './common/footer';
import { bindActionCreators } from 'redux';
import * as ListingActions from '../actions/listing';
import { connect } from 'react-redux';
export default class AppComponent extends React.Component {
render() {
console.log('apps', this.props);
return (
<div>
<HeaderComponent />
{ this.props.children }
<ShareFooterComponent />
<FooterComponent />
</div>
);
}
}
我错过了什么吗?