WhoBuilt

Component First Navigation In React Native

Oct 8, 2019· 15 min· 1.0K views·Watch on YouTube

Speakers

Satyajit Sahoo, who works at Callstack, and Michał Osadnik, who works with Sahoo on React Navigation, present at React Native EU 2019 on a component first navigation API.

Separate navigation state from behavior

Sahoo explains that navigation libraries organize pages, connect them, pass data, and manage navigation state and events. React Navigation separates its core routers from primitives such as stack, tab, and drawer views, which are combined into navigators. The modular approach lets teams replace or improve parts independently and adopt community solutions.

Limits of static configuration

Sahoo says the existing API defines navigators and routes in static configuration outside component rendering. That leaves configuration without access to props, state, or context, making dynamic choices such as an initial route or a set of tabs from server data difficult. Static screen options also make it awkward to connect a header button to a component method.

Define navigators as components

Sahoo announces React Navigation 5 alpha, where navigators render as components and screens are declared as children. Because configuration runs during render, apps can conditionally choose routes, set an initial route from props, or map fetched tasks into tabs. Michał Osadnik notes that conditional routes make onboarding flows declarative, without manually resetting the stack after login.

Hooks, typing, and debugging

Sahoo describes a hooks first design intended to improve type safety and remove higher order component wrappers. Examples include `useNavigation`, `useFocusEffect`, and checking whether a screen is focused. The new TypeScript support offers autocomplete for navigation methods, route names, and parameters, while experimental Redux DevTools integration shows navigation actions and state and supports time travel debugging.

Migration and alpha release

The team planned to maintain the previous React Navigation version and release bug fixes, while offering a compatibility layer to ease migration to the new architecture. Sahoo directs users to reactnavigation.org/next to try the alpha and asks them to report bugs and suggestions.

Takeaways

  • Keep navigation state management separate from the views and behaviors that implement stack, tab, and drawer patterns.
  • Declare routes inside component rendering when they depend on props, state, context, or fetched data.
  • Use conditional screen declarations to express onboarding access rules declaratively.
  • Hooks can expose navigation and focus behavior without adding wrapper components.
  • For a major navigation rewrite, provide migration support while maintaining fixes for the previous version.

Mentioned in this talk

Search inside this talk

What was claimed 12

Show all 12 facts

Related talks