Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass down child routes using context instead of props #5

Closed
oliverwoodings opened this issue Jan 31, 2016 · 1 comment
Closed

Pass down child routes using context instead of props #5

oliverwoodings opened this issue Jan 31, 2016 · 1 comment

Comments

@oliverwoodings
Copy link
Collaborator

Right now if you want to provide additional props to a child route you need to clone it, leading to code like this:

class App extends Component {
  render () {
    return (
      <div>
        {React.cloneElement(this.props.children, { anotherProp: 'foo' })}
      </div>
    )
  }
}

It would be much nicer IMO to have a <RouteHandler /> component like they do in react-router:

class App extends Component {
  render () {
    return (
      <div>
        <RouteHandler anotherProp='foo' />
      </div>
    )
  }
}

This should be pretty easy to achieve. The RouteHandler component would look something like this:

class RouteHandler extends Component {
  static childContextTypes = {
    routes: PropTypes.array
  }
  static contextTypes = {
    routes: PropTypes.array
  }

  getChildContext () {
    return {
      routes: routes.slice(1)
    }
  }

  render () {
    return this.context.routes[0]
  }
}

Thoughts @KidkArolis ?

@KidkArolis
Copy link
Owner

Cleaning up issues of a bunch of repos.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants