RickWong / react-transmit

Relay-inspired library based on Promises instead of GraphQL.
BSD 3-Clause "New" or "Revised" License
1.31k stars 61 forks source link

How to receive props in `createContainer` #72

Open gocreating opened 7 years ago

gocreating commented 7 years ago

How can I receive props from parent component (actually from redux store's connect HOC) inside Transmit.createContainer?

Given a scenario like below:

// UserList.js

class UserList extends Component {
  render () {
    return this.props.users.map(/* ... */);
  }
}

export default Transmit.createContainer(UserList, {
  /* how to receive props (page, dispatch, foo, bar, ...etc.) here? */
  fragments: {
    users (queryParams) {
      return () => userAPI.list({
         page: pageFromProps, // fetch data depending on props
      }).then(users => {
        dispatchFromProps(receiveUsers(users)); // dispatch action creator to update store
        return users;
      });
    },
  },
});
// MainPage.js

class MainPage extends Component {
  render() {
    return (
      <div>
        <UserList
          page={3}
          dispatch={reduxStore.dispatch}
          foo={reduxStore.getState().foo}
          bar={reduxStore.getState().bar}
        />
      </div>
    );
  }
}