react-router icon indicating copy to clipboard operation
react-router copied to clipboard

Call React.render multiple times on the handler

Open nicib83 opened this issue 11 years ago • 5 comments

Am i allowed to call the render method on the handler multiple times on each:

Router.run(routes, function (Handler, state) ... ? React.render(, document.getElementById('example')); i try to update the data prop with some async operations.

i first noticed that willTransitionFrom isn't fired after the first history back/forward navigation. seems like this is because prevRoutes in 355 is empty

nicib83 avatar Dec 18 '14 20:12 nicib83

Am i allowed to call the render method on the handler multiple times

Yes.

seems like this is because prevRoutes in 355 is empty

This was fixed in 90cd7502caa157068849da85e0eec972ec175a19. Please update to version 0.11.6.

mjackson avatar Dec 18 '14 21:12 mjackson

i still got that issue.

i can easily replicate the issue just by calling:

React.render(<Handler data={data}/>, document.getElementById('example'));  
React.render(<Handler data={data}/>, document.getElementById('example'));

twice in a row.

willTransitionFrom won't be called consistently (usually just once)

prevRoutes in create Router is still empty

nicib83 avatar Dec 21 '14 11:12 nicib83

I'm trying understand.

I'm assuming the URL is not changing between renders but you expect willTransitionFrom to be called?

ryanflorence avatar Dec 21 '14 16:12 ryanflorence

Yes, nextState is being reset in updateState, triggered by each render. This prevents willTransitionFrom from being called on subsequent route calls. I don't expect it to be called on each render.

Simply moving the nextState reset before

        nextState.path = path;

Seems to solve it.

On Sunday, December 21, 2014, Ryan Florence [email protected] wrote:

I'm trying understand.

I'm assuming the URL is not changing between renders but you expect willTransitionFrom to be called?

— Reply to this email directly or view it on GitHub https://github.com/rackt/react-router/issues/627#issuecomment-67774962.

nicib83 avatar Dec 21 '14 16:12 nicib83

Ah, gotcha. A failing test case pull request would be invaluable.

Typically I cause a rerender in my root route handler and everything works out, but being able to render the run callback's Handler would be great.

ryanflorence avatar Dec 21 '14 17:12 ryanflorence