Skip to content

react-blogger-apiTyped React hooks for the Blogger API v3

33 hooks, one per documented Blogger API v3 method. Zod-validated responses at the network boundary, cache with automatic invalidation, and tests that never touch the network.

Quick start ​

Install:

bash
npm install react-blogger-api
bash
pnpm add react-blogger-api
bash
yarn add react-blogger-api
bash
bun add react-blogger-api

Wrap your app in BloggerProvider and call a hook:

tsx
import { BloggerProvider, usePosts } from 'react-blogger-api'

function App() {
  return (
    <BloggerProvider config={{ apiKey: 'YOUR_API_KEY', defaultBlogId: '1234567890' }}>
      <PostList />
    </BloggerProvider>
  )
}

function PostList() {
  const { items, isLoading, error } = usePosts({ maxResults: 10 })

  if (isLoading) return <p>Loading…</p>
  if (error) return <p>Failed: {error.message}</p>
  return <ul>{items.map((post) => <li key={post.id}>{post.title}</li>)}</ul>
}

With defaultBlogId set, every blog-scoped hook resolves the blog automatically. Pass options.blogId per hook to override it.

The standalone client works outside React:

ts
import { createBloggerClient } from 'react-blogger-api'

const client = createBloggerClient({ apiKey: 'YOUR_API_KEY' })
const post = await client.posts.get({ blogId: '1234567890', postId: '42' })

Authentication notes ​

  • Reads on public blogs work with apiKey alone.
  • Writes (insert / update / patch / delete / publish / revert) and any read of a private blog require accessToken, sent as Authorization: Bearer <token>.
  • A token can only be used from a server or a trusted environment. Do not ship a long-lived token in browser code; proxy through your own backend or use short-lived tokens.
  • Pass a function for accessToken when the token rotates — it is resolved per request.

Where to go next ​

Guide ​

  • Installation — install steps and peer dependency requirements.
  • Quick Start — renders a post list step by step.
  • Caching — how the built-in QueryStore works.
  • Testing — mock fetch in unit tests.

API ​

  • Providers — BloggerProvider and BloggerTanstackProvider configuration.
  • Hooks — all 33 hooks with signatures.
  • Client — createBloggerClient for non-React call sites.
  • Types — resource, list, param, and ID types.
  • Errors — BloggerApiError and BloggerParseError.

Released under the MIT License.