Skip to content

"passthrough" children don't re-render when parent changes #4067

@matthewmueller

Description

@matthewmueller

Given the following Components with the following implementations:

home.js:

render () {
  return (
    <div className="home">
      <Router>
        <Route path='/'>
          <span>Hi from Index</span>
        </Route>
        <Route path='/user/martin'>
          <span>Hi Martin</span>
        </Route>
      </Router>
    </div>
  )
}

router.js:

componentDidMount () {
    var self = this;

    history.on('pushstate', function(pathname) {
      self.setState({});
    })

    history.on('popstate', function(pathname) {
      self.setState({})
    })
}

render () {
    return React.createElement('div', { className: 'Router' }, this.props.children);
}

route.js:

render () {
  if (!match(this.props.path)) return null;
  return React.createElement('div', { className: 'Route'}, children);
}

I'm running into the situation that since I'm not creating the <Route> in the parent and passing it through from the owner, the children do not re-render when the parent's state changes.

What's the best way around this? Seems like a pretty common use case.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions