Skip to content

Changed props not propagated to route handlers on subsequent renders #358

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

Closed
nnarhinen opened this issue Oct 6, 2014 · 1 comment
Closed

Comments

@nnarhinen
Copy link

Consider following code (live demo at http://jsfiddle.net/raem6o6z/)

var RouteHandler = React.createClass({
    render: function() {
        return React.DOM.div({}, this.props.foo ? 'Is foo' : 'Is not foo');
    }
});

var App = React.createClass({
    getInitialState: function() {
        return {foo: true};
    },
    componentDidMount: function() {
        var self = this;
        setTimeout(function() {
            self.setState({foo: false});
            console.log('setting state');
        }, 2000);
    },
    render: function() {
        return ReactRouter.Routes({},
                                  ReactRouter.Route({
                                      handler: RouteHandler,
                                      foo: this.state.foo
                                  }));
    }
});

React.renderComponent(App(), document.getElementById('app'));

After setting the state App::render is called as well as RouteHandler::render but the props on RouteHandler are not updated, they still point to the initial values.

Is this expected (documented?) behavior? And if so is there something I can do about it. I need to pass changed stuff to the route handlers.

@ryanflorence
Copy link
Member

Currently the only use-case we've programmed to is rendering your routes as the top-level component once, not from within a component.

In other words, you can't render <Routes/> multiple times.

Please see #262, #314

nnarhinen added a commit to nnarhinen/nerve that referenced this issue Oct 7, 2014
storeListener can't be mixed in in the nested route handlers because
changing active route then seem to stop all event listening from all
storeListeners. Noticed this when the notifications stopped working.

Also changed the notification system to use named events emitted by the
stores. This way it became more general.

Also had to introduce a new top level route to handle passing all store
contents down to nested handlers.

See remix-run/react-router#358 and remix-run/react-router#314
@lock lock bot locked as resolved and limited conversation to collaborators Jan 25, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants