martyjs/marty

Fetch state in a container based on the result of another fetch

Closed this issue · 1 comments

I'm wondering if it possible at all when fetching in a container to fetch based on another property that was fetched from a store.

Some example code of what I'm trying to do here:

export default Marty.createContainer(Container, {
  listenTo: ['userStore', 'somethingStore'],
  fetch: {
    user() {
      return this.app.userStore.getUser(this.props.userId);
    },
    somethingElse() {
      if (this.props.user) {
        return this.app.somethingStore.getSomethingElse(this.props.user.someProperty);
      }
    }
  }
});

If I log this.props.user in the somethingElse method, I see that the method is rerun, but this.props.user is always undefined in somethingElse().

The reason I want to do this is that we are trying to only let the pages in the application be "smart components", meaning Marty components, while all other components in the hierarchy are dumb React components.

taion commented

this.props there refers to the props passed into the container. As it's currently set up, I think you'll need to read into the store.