Skip to content

Instantly share code, notes, and snippets.

@c7tincu
Last active August 29, 2015 14:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save c7tincu/c6d7ce60b2f14cebf269 to your computer and use it in GitHub Desktop.
Save c7tincu/c6d7ce60b2f14cebf269 to your computer and use it in GitHub Desktop.

So I needed to transfer the routing context (I’m using react-router) from component X to component ContactsEditDialog, as it’s rendered in some remote area of the DOM tree (#modal), not under the node corresponding to component X, as usual...

So I basically replaced this...

React.withContext({ router: this.context.router }, () => {
  React.render(
    <ContactsEditDialog { ...this.props } { ...i18nData }/>,
    document.getElementById('modal')
  );
});

...with this...

var router = this.context.router;
var ContactsEditDialogWrapper = React.createClass({
  childContextTypes: {
    router: React.PropTypes.func.isRequired
  },
  getChildContext() {
    return { router: router };
  },
  render() {
    return <ContactsEditDialog { ...this.props } { ...i18nData }/>;
  }
});
React.render(
  <ContactsEditDialogWrapper { ...this.props }/>,
  document.getElementById('modal')
);

...all because React.withContext() is marked as deprecated...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment