Skip to content

Support contexts for easier integration with React Router#21

Merged
ericclemmons merged 5 commits into
masterfrom
21-contexts
Apr 14, 2015
Merged

Support contexts for easier integration with React Router#21
ericclemmons merged 5 commits into
masterfrom
21-contexts

Conversation

@ericclemmons
Copy link
Copy Markdown
Owner

Resolver.createContainer(Fixture, {
  contextTypes: {
    router: React.PropTypes.func
  },

  resolve: {
    users: (props, context) => fetch(`/api/users/${context.params.userId}`)
  }
});

@iamdustan
Copy link
Copy Markdown
Contributor

Would this be done with the following:

  static createContainer(Component, props = {}) {
    // ...
    Object.assign(Component.contextTypes, props.contextTypes);

    class ComponentContainer extends React.Component {

@ericclemmons
Copy link
Copy Markdown
Owner Author

Pretty much, yep!

@ericclemmons
Copy link
Copy Markdown
Owner Author

Well, one caveat. I don't want to alter the behavior of the underlying Component, so the props and context will only be available for the resolving function(props, context) { ... } for loading the data.

The original function should remain unaltered.

ericclemmons added a commit that referenced this pull request Apr 14, 2015
Support contexts for easier integration with React Router
@ericclemmons ericclemmons merged commit 8f1d0dc into master Apr 14, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants