Wrapping the App with Custom Providers
You can wrap your React Native app with your own React component. It sits at the very top of the component tree, above every page, so anything it provides is available to the whole app.
Use it when a library needs a provider or a root-level component to work, for example:
- Data fetching and caching: TanStack Query, SWR, Apollo Client (GraphQL)
- State management: Redux, Jotai, Recoil
- Gestures, sheets and overlays:
GestureHandlerRootView, bottom sheets, portals, toast messages - Error and crash reporting: Sentry, Bugsnag error boundaries
- Analytics and feature flags: Segment, PostHog, LaunchDarkly
- SDKs that need a provider: payments (Stripe), authentication (Auth0)
- One-time setup at app start: configuring an SDK before the app renders
Adding a custom wrapper
- In Studio, create a file named
customapp.wrapper.jsin thesrc/main/webappfolder of your project. - Export a default React component from this file. The component receives a
childrenprop and must render it, wrapped in whatever your app needs.
note
If your wrapper uses a third-party library, such as TanStack Query, add its npm package in the Plugins section first. See Third-party expo plugins.
Example: TanStack Query
The following wrapper makes a QueryClient available to the whole app:
Components that use TanStack Query hooks such as useQuery can now share cached responses. They skip re-rendering when the data hasn't changed.
tip
You can nest as many providers as you need inside CustomAppWrapper. Make sure children is rendered by the innermost one.