npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

simple-react-seo

v1.0.12

Published

A React library for managing SEO metadata on a per-page basis

Readme

alt text

Simple React SEO

A TypeScript React library for managing SEO metadata on a per-page basis. This library provides components to easily set and manage SEO-related tags in your React application.

Installation

npm install simple-react-seo
# or
yarn add simple-react-seo

Features

  ✅ TypeScript support

  ✅ Per-page SEO management

  ✅ Support for Open Graph and Twitter card metadata

  ✅ JSON-LD structured data support

  ✅ SEO context provider

  ✅ Customizable meta tags

  ✅ Canonical URL support

  ✅ Robots directives (noindex, nofollow)

Usage

Basic Setup

Wrap your application with the SEOProvider component and add the SEOHead component to your document head:

// _app.tsx (Next.js) or App.tsx (React)
import React from "react";
import { SEOProvider, SEOHead } from "simple-react-seo";

const defaultSEO = {
  title: "My Website",
  description: "A website built with Simple React SEO",
  keywords: "my website, website",
  openGraph: {
    type: "website",
    siteName: "My Website",
  },
  twitter: {
    cardType: "summary_large_image",
    handle: "@myhandle",
    site: "@mysite",
  },
};

function MyApp({ Component, pageProps }) {
  return (
    <SEOProvider defaultSEO={defaultSEO}>
      {/* Add SEOHead in your document head */}
      <SEOHead />
      <Component {...pageProps} />
    </SEOProvider>
  );
}

export default MyApp;

Using with Next.js

For Next.js applications, use it in your _app.tsx and _document.tsx files:

// _document.tsx
import Document, { Html, Head, Main, NextScript } from "next/document";
import { SEOHead } from "simple-react-seo";

class MyDocument extends Document {
  render() {
    return (
      <Html>
        <Head>
          <SEOHead />
        </Head>
        <body>
          <Main />
          <NextScript />
        </body>
      </Html>
    );
  }
}

export default MyDocument;

Per-page SEO

Use the PageSEO component in your page components to set page-specific SEO:

// pages/about.tsx
import React from "react";
import { PageSEO } from "simple-react-seo";

const AboutPage = () => {
  return (
    <>
      <PageSEO
        seo={{
          title: "About Us | My Website",
          description: "Learn more about our company",
          openGraph: {
            title: "About Our Company",
            image: {
              url: "https://example.com/about-image.jpg",
              alt: "About Us",
              width: 1200,
              height: 630,
            },
          },
        }}
      />
      <div>
        <h1>About Us</h1>
        <p>This is the about page content.</p>
      </div>
    </>
  );
};

export default AboutPage;

Using JSON-LD Structured Data

// pages/product.tsx
import React from "react";
import { PageSEO } from "simple-react-seo";

const ProductPage = ({ product }) => {
  const productJsonLd = {
    "@context": "https://schema.org",
    "@type": "Product",
    name: product.name,
    image: product.image,
    description: product.description,
    sku: product.sku,
    offers: {
      "@type": "Offer",
      priceCurrency: "USD",
      price: product.price,
      availability: "https://schema.org/InStock",
    },
  };

  return (
    <>
      <PageSEO
        seo={{
          title: `${product.name} | My Store`,
          description: product.description,
          jsonLd: productJsonLd,
        }}
      />
      <div>
        <h1>{product.name}</h1>
        <p>{product.description}</p>
        <p>${product.price}</p>
      </div>
    </>
  );
};

export default ProductPage;

Using the SEO Hook

You can also use the useSEO hook to access or update SEO data programmatically:

import React, { useEffect } from "react";
import { useSEO } from "simple-react-seo";

const DynamicPage = ({ pageData }) => {
  const { updateCurrentSEO } = useSEO();

  useEffect(() => {
    // Update SEO when pageData changes
    updateCurrentSEO({
      title: pageData.title,
      description: pageData.description,
      canonical: pageData.url,
    });

    // Clean up is handled automatically when component unmounts
  }, [pageData, updateCurrentSEO]);

  return (
    <div>
      <h1>{pageData.title}</h1>
      <div dangerouslySetInnerHTML={{ __html: pageData.content }} />
    </div>
  );
};

export default DynamicPage;

API Reference

Components

SEOProvider

The provider component that wraps your application and provides SEO context.

Props:

  • defaultSEO (required): Default SEO metadata for all pages
  • children (required): Child components

SEOHead

Component that renders SEO tags in the document head.

Props:

  • additionalElements (optional): Additional React elements to insert in the head

PageSEO

Component to set page-specific SEO metadata.

Props:

  • seo (required): SEO metadata for the page
  • merge (optional, default: true): Whether to merge with default SEO or replace it entirely

Hooks

useSEO()

Hook to access and update SEO data within components.

Returns:

  • defaultSEO: Default SEO metadata
  • currentSEO: Current page's SEO metadata
  • updateCurrentSEO(seo): Function to update current SEO
  • clearCurrentSEO(): Function to clear current SEO

TypeScript Types

The library exports TypeScript types for all properties:

import {
  SEOMetadata,
  OpenGraphMetadata,
  TwitterMetadata,
  MetaTag,
} from "simple-react-seo";

// Example usage
const mySEO: SEOMetadata = {
  title: "Page Title",
  // ...other properties
};

License

MIT