Skip to content

React's getChildContext doesn't set child context properly? #2

Description

@TimFletcher

If I have a simple root component in React

AppLayout = React.createClass({

  childContextTypes: {
    muiTheme: React.PropTypes.object
  },

  getChildContext: function() {
    return {
      muiTheme: ThemeManager.getCurrentTheme()
    };
  },

  render() {
    return (
      <div>
        { this.props.content }
      </div>
    )
  }
});

And a FlowRouter / ReactLayout setup like this

FlowRouter.route('/register', {
  name: 'register',
  action: function(params) {
    ReactLayout.render(AppLayout, { content: <AuthRegisterPage /> });
  }
});

Then within the render() method of AuthRegisterPage, this.context is undefined. However, if I don't use { this.props.content } and simply have <AuthRegisterPage /> within the AppLayout component then this.context returns {muiTheme: someobject} as I'd expect.

I'm not a react expert by any means. Am I missing anything?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions