store.js
const defaultState = {
headerData
};
const store = createStore(rootReducer, defaultState));
export default store;
rootReducer Here is the .js file in which all the reducers are combined.
HeaderComponent.js
class HeaderComponent extends React.Component {
constructor...
handleClick...
render...
}
function mapStateToProps (state) {
return {
headerData: state.headerData
};
}
export default connect(mapStateToProps)(HeaderComponent);
NavComponent.js
class NavComponent extends React.Component {
constructor...
handleClick...
render...
}
function mapDispatchToProps (dispatch) {
return bindActionCreators(navActions, dispatch);
}
export default connect(mapDispatchToProps)(NavComponent);
In this case, your NavComponent has access to all the actions from your file navActions. To do this, you need to create a js file navActions.
You HeaderComponent are displayed in the repository headerDatawhen you create the moment in store.js. To do this, you need to create a .js file headerData.
, , NavComponent, headerData , HeaderComponent .
Basics Redux Documentation, , .