Thread-safe Async React Helmet

3.0.0 · active · verified Sun Apr 19

react-helmet-async is a robust solution for managing document head tags (title, meta, link, etc.) in React applications, designed to be thread-safe for server-side rendering (SSR). It addresses the limitations of the original `react-helmet` by encapsulating state on a per-request basis through a `<HelmetProvider>`, crucial for asynchronous SSR environments. The current stable version is 3.0.0, which introduces significant adaptations for React 19+, leveraging React's native metadata hoisting capabilities while maintaining backward compatibility for React 16-18. It differentiates itself by providing a consistent API across React versions, handling `htmlAttributes` and `bodyAttributes` consistently, and offering a context for SSR data extraction, although this context behaves differently in React 19. Releases appear to follow a non-strict cadence, driven by major React version updates and feature enhancements.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates basic client-side usage of Helmet for managing document head attributes, title, meta, link, style, and script tags within a React application, wrapped in a HelmetProvider.

import React from 'react';
import { createRoot } from 'react-dom/client';
import { Helmet, HelmetProvider } from 'react-helmet-async';

const App = () => (
  <div>
    <Helmet>
      <html lang="en" amp />
      <title>My Awesome App</title>
      <meta name="description" content="A basic example of react-helmet-async." />
      <link rel="canonical" href="https://example.com/" />
      <style>{`body { background-color: #f0f0f0; }`}</style>
      <script type="application/ld+json">
        {
          "@context": "https://schema.org",
          "@type": "WebSite",
          "url": "https://example.com/",
          "name": "My Awesome App"
        }
      </script>
    </Helmet>
    <h1>Welcome to My Awesome App!</h1>
    <p>Check the document head for meta tags.</p>
  </div>
);

const rootElement = document.getElementById('app');
if (rootElement) {
  createRoot(rootElement).render(
    <HelmetProvider>
      <App />
    </HelmetProvider>
  );
} else {
  console.error('Root element #app not found!');
}

view raw JSON →