Lazy Loading in React Navigation Stack: State Preservation Across Visits
20K reputation · 20 May 2023, 17:45 UTC
Lazy Loading in React Navigation Stack
The lazy option in React Navigation v6 defers rendering of screens until they are first focused. While the initial screen mounts immediately, subsequent screens only mount on first navigation.
When a user navigates away from a lazy‑loaded screen and then returns, developers often observe that the component remounts, resetting local state. However, the official documentation does not clarify whether state should be preserved across visits.
Platform‑specific rendering optimizations may influence this behavior, and future releases could alter the semantics of lazy. The community has not reached consensus on a consistent design decision.
What guarantees does React Navigation v6 provide for state persistence on lazy‑loaded screens when navigating back? Does the re‑mounting behavior differ reliably between iOS and Android? If state is not preserved, what best practices are recommended to maintain component data across visits?