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

react-wp-post

v3.3.7

Published

React components for rendering WordPress posts, pages, categories, WooCommerce products, comments, and more

Downloads

72

Readme

react-wp-post

A powerful, headless React component library designed to connect seamlessly with the WordPress REST API and WooCommerce REST API. It includes ready-to-use hooks and Tailwind CSS-powered components for rapidly building WordPress frontends in React.

Features

  • Built-in Data Fetching: Provides data hooks like useWpPosts, useWpPost, useWcProducts, etc.
  • Headless WordPress & WooCommerce: Read articles, loop product grids, list categories, post threaded comments, and natively render author biographies.
  • Tailwind CSS Ready: Extremely customizable layouts using embedded Tailwind CSS utility classes.
  • Flexible Layouts: Effortlessly switch your post loops through grid, list, compact, and full layouts out of the box.
  • Context API Context: Centrally configure your remote WordPress URL and API keys without prop drilling.

Installation

Install the package via npm:

npm install react-wp-post

Tailwind CSS Configuration

Because this library ships with raw Tailwind CSS class names inside its components, your project's tailwind.config.js must scan the package to dynamically build the corresponding styles.

Add react-wp-post to your content array inside tailwind.config.js:

export default {
  content: [
    "./src/**/*.{js,ts,jsx,tsx}",
    // Add this line to scan the library for CSS classes
    "./node_modules/react-wp-post/**/*.js"
  ],
  theme: {
    extend: {},
  },
  plugins: [],
}

Quick Start

1. Setup the WordPress Provider

Wrap your React application (or specific route) with the <WpProvider> to configure the remote endpoint.

Alternatively, you can skip passing siteUrl as a prop if you define it in your .env file! We automatically detect:

  • VITE_WP_SITE_URL (Vite)
  • NEXT_PUBLIC_WP_SITE_URL (Next.js)
  • REACT_APP_WP_SITE_URL (Create-React-App)
import { WpProvider } from 'react-wp-post';

function App() {
  return (
    <WpProvider 
      // If VITE_WP_SITE_URL is in .env, you can omit the siteUrl prop perfectly!
      siteUrl="https://your-wordpress-site.com"
      
      // Optional: Add WooCommerce keys if you plan to use WcProduct components
      // Also automatically detected via VITE_WC_CONSUMER_KEY & VITE_WC_CONSUMER_SECRET
      wcConsumerKey="ck_your_woo_key"
      wcConsumerSecret="cs_your_woo_secret"
    >
      <MyBlogPage />
    </WpProvider>
  );
}

export default App;

2. Basic Example: Listing Posts

You can quickly fetch and render a list of WordPress posts using the <WpPostList /> component. Switch between layouts effortlessly using the layout prop!

import { WpPostList } from 'react-wp-post';

function MyBlogPage() {
  return (
    <div className="container mx-auto p-6">
      <h1 className="text-3xl font-bold mb-8">Latest News</h1>
      
      {/* 
        The layout prop transforms the card design.
        Options: "grid" | "list" | "compact"
      */}
      <WpPostList 
        layout="grid" 
        params={{ per_page: 6, _embed: true }} 
      />
    </div>
  );
}

3. Basic Example: Individual Post details

Fetch and render a specific individual WordPress post, complete with content structure, authors, timestamps, categories, and tags.

import { WpPost, WpComments, WpShare } from 'react-wp-post';

function SinglePostView({ postId }) {
  return (
    <div className="max-w-4xl mx-auto p-4">
      <WpPost id={postId} layout="full" />
      
      {/* Easily drop in social sharing elements */}
      <WpShare 
        url="https://your-frontend-url.com/post/current" 
        title="Check out this post" 
      />

      <hr className="my-10" />

      {/* Integrate the threaded commenting system easily */}
      <WpComments postId={postId} />
    </div>
  );
}

4. Basic Example: WooCommerce

If you configured your provider with WooCommerce keys, fetch and map eCommerce widgets directly.

import { WcProductList } from 'react-wp-post';

function StoreFront() {
  return (
    <div className="store">
      <h2 className="text-2xl font-bold">Featured Products</h2>
      <WcProductList grid mixBlend />
    </div>
  );
}

Available Components

  • Hooks: useWpPosts, useWpPost, useWpCategories, useWpPage, useWpMedia, useWpComments, usePostComment, useWpTags, useWpAuthor, useWcProducts, useWcProduct, useWcProductCategories.
  • WordPress Core: <WpPost />, <WpPostList />, <WpPage />, <WpCategory />, <WpMedia />
  • WooCommerce: <WcProduct />, <WcProductList />, <WcProductCategory />
  • User Engagement: <WpComments />, <WpShare />, <WpAuthor />, <WpTags />

Component Props Reference

<WpPost /> & <WpPostList />

| Prop | Type | Default | Description | |------|------|---------|-------------| | layout | 'grid' \| 'list' \| 'compact' \| 'full' | 'full' | The visual layout of the post. | | LinkComponent | React.ElementType | undefined | Custom link component (e.g. Link from react-router-dom). | | baseUrl | string | '/blog' | Prefix for the post detail links. | | imageClassName | string | '' | Custom classes for the img tag. | | imageContainerClassName | string | '' | Custom classes for the image wrapper/link. | | itemClassName | string | '' | Custom classes for each individual post item card. | | showExcerpt | boolean | false | Show the post excerpt. | | showContent | boolean | true | Show the full content. | | showAuthor | boolean | true | Show author info. | | showDate | boolean | true | Show post date. | | showCategories | boolean | true | Show category labels. | | showTags | boolean | true | Show tag labels (full layout only). |

<WcProduct /> & <WcProductList />

| Prop | Type | Default | Description | |------|------|---------|-------------| | imageClassName | string | '' | Custom classes for the product img tag. | | imageContainerClassName | string | '' | Custom classes for the image wrapper. | | itemClassName | string | '' | Custom classes for each product card in a list. | | grid | boolean | true | (WcProductList only) Whether to show in a grid. | | showPrice | boolean | true | Show product price. | | showRating | boolean | true | Show average rating. | | showDescription | boolean | true | Show short description. |