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-rest-api-provider

v0.0.5

Published

React Component for WordPress Rest API using provider - consumer pattern.

Readme

react-wp-rest-api-provider

React component with provider - consumer pattern, making it easy to pass data to you components.

Installation

Install the package from npm.

npm install -S react-wp-rest-api-provider

Usage

Provider

Wrap your application with RestApiProvider component.

import RestApiProvider from 'react-wp-rest-api-provider'
const App = () => (
  <RestApiProvider base="/wp-json/wp/v2">
    <YourApp />
  </RestApiProvider>
)

Consumer

Then inside your application where you need to request your data from rest API, use the RestApiRequest consumer component.

The component accepts two properties.

path property

A property defining rest API route. This property should be given as a string. For example for getting default WordPress articles you sould give the value "posts".

queryParams property

A property containg JSON object including desired query parameters. For example to get 1st 10 posts you can give {page: 1, per_page: 10}. To know what paramaters can be used see the agrs defined for your endpoint using GET method.

Data from consumer

Wrap you presentational component with RestApiRequest consumer component. It returns 4 properties to it's children which you can use. The properties are data, headerEntries, loading, error

  • data is an array containing fetched data. For example post items.
  • headerEntries contain headers from the response. See then Pagination section bellow.
  • loading is a boolean value, indicating the status of the request.
  • error is an object containing information about the error that might have occured during the request.

Example code

import { RestApiRequest } from 'react-wp-rest-api-provider'
const PostList = () => (
  <RestApiRequest path={'posts'} queryParams={{page: 1, per_page: 10}}>
    {({ data, headerEntries, loading, error }) => {

      if (error) return <p>Error</p>;
      if (loading) return <p>Loading...</p>;
      return (
          <YourPresentationalComponent
              data={data}
              headerEntries={headerEntries}
          />
      );
    }}
  </RestApiRequest>
)

Pagination information

The reason I created this package is that most of existing packages with similar functionality did not support WordPress way of dealing with pagination. The pagination information is returned in the headers of the rest API response. To get pagination information see the x-wp-totalpages and x-wp-total entries in the headerEntries returned by the component.

Is this legacy code?

This project is done because sometimes you are limited to legacy way of doing things. If you are looking something more sexy see the WPGraphQL plugin and Apollo Client.