Reputation: 2830
I try to learn react/redux by myself by developing a sample project. I have an angular.js & backend background.
Instead of huge copy-paste of files, I wanted to share my progress on github: https://github.com/tolgafiratoglu/react-social-network
My progress so far:
I dispatch user action in constructor of Home component, like this:
store.dispatch(userActions.getAuthenticatedUser())
What I'm stuck is, I can't figure out how to access store data in router components (like Home). I simply want to pass user id to ProfileGroupsWidget, after the data retrieved.
Upvotes: 0
Views: 50
Reputation: 184
Assuming you want to access store value inside the Home component. In order to consume the store state first, you need to pass the store state through wrapping it up inside the Provider which pass state to all the child component. And then you child component (Assuming=Home). You can write the following line as :
export default connect(mapStateToProps, mapDispatchToProps)(Login)
and then write a function before that
const mapStateToProps = state => ({ todoList: state.todos })
after that, you can access your props like:
this.props.todoList
Upvotes: 2