//index.js
import React, { Component } from 'react';
import ReactDOM from 'react-dom';
import { Provider } from 'react-redux';
import { createStore } from 'redux';
import reducer from './reducers';
/**
* Components
*/
import Settings from './components/settings/Settings';
import User from './components/user/User';
const store = createStore( reducer, window.__REDUX_DEVTOOLS_EXTENSION__ && window.__REDUX_DEVTOOLS_EXTENSION__() );
export default class Root extends Component {
render() {
return (
<Provider store={store}>
<User />
<Settings />
</Provider>
)
}
}
ReactDOM.render( <Root />, document.getElementById( 'root' ) );
//User.js
export default connect(
state => ({
testStore: state
}),
dispatch => ( {
onLoadData: ( data ) => {
dispatch( { type: 'GET_USER_DATA', data: data } );
}
} )
)( User );
//Settings.js
class AutoCompleteExampleSimple extends Component {
componentDidMount() {
console.log( this.props.testStore ) // {}
setTimeout(() => {
console.log( this.props.testStore ) // {...data}
}, 2000)
}
}