I have the following code:
<View>
<Header />
<List />
</View>
If the user clicks on an edit button in a list item, react-router
changes the page from /list
to /list/{itemId}
. This is a new page. After the user filled in some information and clicks on save, react-router
changes back to /list
. Now the full /list
-page is rerendered!
Is there a way to cache a page, so react
can detect the changes and rerender only them instead of the full page again?
It should also be possible to render the page directly (not over /list
-> /list/{itemId}
) so no modal
solution I think.
I'm using react-router-redux v5.0.0-alpha.9
so the solution should be compatible with it. It should also be compatible with react-native
and react-dom
.
<Route>
component does have arender
prop that you could use to show/hide the component rather than the default behavior of unmounting it when navigating to a new route. See github.com/ReactTraining/react-router/issues/4888. I'm not sure what timdorr meant by "that will have unintended side effects most likely" but I imagine that in cases like this it should be fine (unless you're doing it all over the place). – Boche