MobX React TypeError: Cannot read property of undefined

Viewed 4642

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.

1 Answers
Related