Reputation: 5260
I am trying React with MobX.
I defined fetchSources()
in my store.
If I put the following at the top level component it works fine.
componentWillMount() {
this.props.store.fetchSources()
}
But if I put the above same code into child level component which is also defined as an observer it gives me the following error.
TypeError: Cannot read property 'fetchSources' of undefined.
Any idea as to how to fix it?
Update:
Tholle is correct. The problem is resolved by passing the store to the child component.
Upvotes: 3
Views: 4839
Reputation: 112897
Make sure you pass the fetchSources
as a prop to the child component as well, and it should work.
Upvotes: 1