react-native-helmet-async is a specialized fork of `react-helmet-async`, which itself is a modern, thread-safe solution for managing meta tags in React applications. This particular package addresses the specific needs of React Native by removing the `react-dom` peer dependency, making it suitable for environments where DOM rendering is not present. Its core differentiator is the use of a `<HelmetProvider>` component to encapsulate Helmet state on a per-request or per-tree basis, crucial for asynchronous server-side rendering (SSR) to prevent state pollution across requests. It is currently at version 2.0.4 and appears to be actively maintained, providing an essential tool for SEO and head management in React Native web applications (when used with a web renderer) and isomorphic React projects where `react-dom` is not desired. It solves the thread-safety issues inherent in the original `react-helmet`'s `react-side-effect` dependency.
npm install react-native-helmet-asyncVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates basic client-side usage of Helmet and HelmetProvider to manage document head tags.
Change `import Helmet from 'react-native-helmet-async';` to `import { Helmet } from 'react-native-helmet-async';`Wrap your root component or the relevant part of your application with `<HelmetProvider>`. For SSR, ensure you pass a `context` prop to the provider.
Replace `Helmet.renderStatic()` calls with extracting `helmetContext.helmet` after rendering the app wrapped in `<HelmetProvider context={helmetContext}>`.Ensure you understand the specific purpose of this fork. If you need `react-dom`, consider `react-helmet-async`. If you're building for React Native (and a web platform through a renderer), this is appropriate.
Add `HelmetProvider.canUseDOM = false;` in your test setup or before rendering components that use Helmet in a Jest environment.
Change `import Helmet from 'react-native-helmet-async';` to `import { Helmet } from 'react-native-helmet-async';`Wrap your application or the specific components using `Helmet` with `<HelmetProvider>`.
Ensure `const helmetContext = {};` is defined and passed as `<HelmetProvider context={helmetContext}>`. After rendering, access properties via `helmetContext.helmet.title.toString()` etc.