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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@snapwp/next

v0.4.0

Published

Utility functions and components for SnapWP application

Downloads

59

Readme

@snapwp/next

Next.js-specific utilities and frontend components for integrating with SnapWP and headless WordPress.

[!WARNING] 🐉 There be dragons! This project is in active development and considered experimental. Some features may be incomplete, unstable, or subject to change.

Installation

Run the following command:

npm install @snapwp/next

Usage

<Parse />

The Parse component converts raw HTML strings into React components, replacing specific elements with custom Next.js components.

Key Features:

  • Replaces <a> tags with the custom Link component for better navigation handling.
  • Replaces <img> tags with the Image component, ensuring optimized image loading and attribute handling.
  • Extracts and applies styles using getStyleObjectFromString.
  • Determines image dimensions using getImageSizeFromAttributes.

Props:

  • html: A string containing HTML to be parsed and rendered as React elements.

This component ensures safe and optimized rendering of dynamic HTML content.

import Parse from '@snapwp/next';

const htmlString = `
    <div>
        <a href="/about" style="color: blue;">About Us</a>
        <img src="/image.jpg" alt="Placeholder Image" />
    </div>
`;

export default function HtmlParserExample() {
    return <Parse html={htmlString} />;
}

<Image />

The Image component wraps Next.js' Image with additional functionality for handling WordPress media items dynamically. It supports automatic width and height calculations, fill mode for flexible layouts, and integration with SnapWP's configuration for optimized image loading.

Props:

  • alt: Alternative text for accessibility.
  • className: CSS class for styling.
  • fill: If true, the image fills the container.
  • fetchPriority: Controls browser image loading priority (high, low, auto).
  • height: Image height (optional, auto-calculated if not provided).
  • image : Media item containing the image details.
  • priority: Loads the image with higher priority.
  • sizes: Defines responsive image sizes for optimization.
  • src: Image URL.
  • width: Image width (optional, auto-calculated if not provided).

If the image source is external or missing proper dimensions, the component gracefully falls back to using a standard <img> tag.

import Image from '@snapwp/next';

export default function CustomImage() {
    return (
        <Image
          src="image-url.jpg"
          alt="Description of the image"
          height={200}
          width={300}
          className="image-class"
          style={{ borderRadius: '8px' }}
        />
    );
}

<Link />

The Link component wraps Next.js' Link to map both internal and external links. Full-qualified links to the WordPress backend are automatically transformed into frontend-relative URLs.

Props:

  • children: The link text or elements.
  • className: CSS class for styling.
  • href: The destination URL.
  • style: Inline styles for customization.

If the link is external, the component renders a standard <a> tag. Otherwise, it leverages Next.js' <Link> for optimized client-side navigation.

import Link from '@snapwp/next';

export default function CustomLink() {
    return (
        <Link href="https://example.com" className="link-class" style={{ color: 'blue' }}>
          Click here
        </Link>

    );
}

<Script>

The Script component is a flexible wrapper around Next.js' <Script>, allowing for controlled execution of scripts with additional inline data.

Props:

  • after: The inline code to be run after the asset is loaded..
  • before: The inline code to be run before the asset is loaded..
  • extraData: Extra information needed for the script
  • handle: A unique identifier for the script.
  • loadingStrategy: Determines how the script is loaded (ASYNC, DEFER).
  • groupLocation: Defines where the script should be loaded (header or footer).
  • src: The source of the asset.

This component ensures better script management, allowing inline execution before or after the main script while supporting external script sources.

import Script from '@snapwp/next';

export default function ScriptExample() {
    return (
        <div>
            <h1>Custom Script Component</h1>
            <Script
                src="https://example.com/main.js"
                handle="example-main-script"
                loadingStrategy="ASYNC"
                groupLocation="HEADER"
            />
        </div>
    );
}

<ScriptModule>

The ScriptModule component loads a WordPress-registered script module, along with its dependencies.

Props:

  • extraData: Extra information needed for the script.
  • handle: A unique identifier for the script.
  • dependencies: Dependencies required by the script module .
  • src: The source URL for the script module.

This component ensures that all dependencies are loaded asynchronously and before the main script loads.

import ScriptModule from '@snapwp/next';

export default function ScriptModuleExample() {
    return (
        <div>
            <h1>Custom ScriptModule Component</h1>
            <ScriptModule
                src="https://example.com/main.js"
                handle="example-main-script"
                dependencies={[
                    {
                        importType: 'STATIC',
                        connectedScriptModule: {
                            handle: '@module',
                            src: 'http://example.com/index.min.js'
                        }
                    }
                ]}
            />
        </div>
    );
}

<Fonts />

The Fonts component is used to correctly parse and output the WordPress-generated font face data.

Props:

  • renderedFontFaces: font face data as a string.

renderedFontFaces receives the list of @font-face CSS to load fonts (with URLs to font files)..

import Fonts from '@snapwp/next';

const fontfaceString =
    "<style class='wp-fonts-local'>\n" +
     "@font-face{font-family:Manrope;font-style:normal;font-weight:200 800;font-display:fallback;src:url('http://example.com/font1.woff2') format('woff2');}\n" +
    "</style>\n"

export default function CustomFonts() {
    return (
        <Fonts renderedFontFaces={fontfaceString} />
    );
}

getGlobalStyles()

Global styles can be modified by passing the getGlobalStyles attribute to the RootLayout within the src/app/layout.tsx file of the frontend application.

getGlobalStyles takes an async callback function that returns an object containing global styles.

The default definition for getGlobalStyles function passed in getGlobalStyles attribute can be found in @snapwp/query package.

Type Definition of getGlobalStyles:

type getGlobalStyles = () => Promise< GlobalHeadProps >;

Type definition of GlobalHeadProps can be found in @snapwp/core package.

getTemplateData()

Template data can be modified by passing getTemplateData attribute to the TemplateRenderer within src/app/[[...path]]/page.tsx file of the frontend application.

getTemplateData takes an async callback to get template styles and content.

The default definition for getTemplateData function passed in getTemplateData attribute can be found in @snapwp/query package.

Type Definition of getTemplateData:

type getTemplateData = ( uri: string ) => Promise< TemplateData >;

Type definition of TemplateData can be found in @snapwp/core package.

Contributing

This package is part of SnapWP's monorepo and is actively maintained by rtCamp. Packages are published to npm from the packages directory, and can be used standalone in the headless WordPress ecosystem or as part of SnapWP's framework.

Contributions are welcome and encouraged! To learn more about contributing to this package or SnapWP as a whole, please read the Contributing Guide.

For development guidelines, please refer to our Development Guide.

Want to expand what's possible with WordPress?