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

use-bluesky

v0.0.4

Published

React hooks to interact with the Bluesky API

Readme

🦋 use-bluesky

React hooks to interact with the Bluesky API.

npm NPM npm Coveralls github codecov CircleCI Known Vulnerabilities Twitter Follow

Install

Via npm

npm install use-bluesky

Via Yarn

yarn add use-bluesky

Requirements

This library requires the following peer dependencies to be installed in your project:

npm install @atproto/api@>=0.10 @atproto/oauth-client-node@>=0.2 @tanstack/react-query@>=5.0 react@>=16.8 react-dom@>=16.8

Or if you're using Yarn:

yarn add @atproto/api@>=0.10 @atproto/oauth-client-node@>=0.2 @tanstack/react-query@>=5.0 react@>=16.8 react-dom@>=16.8

How to use

Setup

App Router

First, wrap your app with the BlueskyProvider and configure it with your Bluesky credentials:

// app/providers.tsx
'use client'

import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
import { BlueskyProvider } from 'use-bluesky'

// Create a client
const queryClient = new QueryClient()

export function Providers({ children }: { children: React.ReactNode }) {
  return (
    <QueryClientProvider client={queryClient}>
      <BlueskyProvider
        baseUrl="https://public.api.bsky.app" // Optional: defaults to this URL
        token="your-bluesky-token" // Optional: for authenticated requests
        queryClient={queryClient} // Optional: pass your own QueryClient instance
      >
        {children}
      </BlueskyProvider>
    </QueryClintProvider>
  )
}

Then, add the provider to your root layout:

// app/layout.tsx
import { Providers } from './providers'

export default function RootLayout({
  children,
}: {
  children: React.ReactNode
}) {
  return (
    <html lang="en">
      <body>
        <Providers>{children}</Providers>
      </body>
    </html>
  )
}

Pages Router

For Next.js Pages Router, you can set up the providers in your _app.tsx:

// pages/_app.tsx
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
import type { AppProps } from 'next/app'
import { BlueskyProvider } from 'use-bluesky'

// Create a client
const queryClient = new QueryClient()

export default function App({ Component, pageProps }: AppProps) {
  return (
    <QueryClientProvider client={queryClient}>
      <BlueskyProvider
        baseUrl="https://public.api.bsky.app" // Optional: defaults to this URL
        queryClient={queryClient} // Optional: pass your own QueryClient instance
        token="your-bluesky-token" // Optional: for authenticated requests
      >
        <Component {...pageProps} />
      </BlueskyProvider>
    </QueryClientProvider>
  )
}

Available Hooks

useProfile

Fetch a user's profile information:

'use client'

import { useProfile } from 'use-bluesky'

export default function ProfilePage({ handle }: { handle: string }) {
  const { data, isLoading, error } = useProfile({
    actor: handle,
  })

  if (isLoading) return <div>Loading...</div>
  if (error) return <div>Error loading profile</div>

  return (
    <div>
      <h1>{data.displayName}</h1>
      <p>{data.description}</p>
    </div>
  )
}

useFollow

Note: In order to use this hook you need to have an authenticated Bluesky account that triggers the action. In order to support that, you need to proxy the request through your own API (baseUrl on BlueskyProvider) that applies the appropriate credentials to the request to the Bluesky API.

Follow or unfollow a user:

'use client'

import { useFollow } from 'use-bluesky'

export default function FollowButton({
  did,
  followUri,
}: {
  did: string
  followUri: string
}) {
  const { follow, unfollow, isPending } = useFollow({
    did,
    followUri,
    onSuccess: () => {
      // Handle successful follow/unfollow
    },
  })

  return (
    <button onClick={() => follow()} disabled={isPending}>
      Follow
    </button>
  )
}

useFollowers

Get a user's followers:

'use client'

import { useFollowers } from 'use-bluesky'

export default function FollowersList({ handle }: { handle: string }) {
  const { data, fetchNextPage, hasNextPage, isFetchingNextPage } = useFollowers(
    {
      actor: handle,
      limit: 50,
    },
  )

  return (
    <div>
      {data?.pages.map((page, i) => (
        <div key={i}>
          {page.followers.map((follower) => (
            <div key={follower.did}>{follower.displayName}</div>
          ))}
        </div>
      ))}
      {hasNextPage && (
        <button onClick={() => fetchNextPage()} disabled={isFetchingNextPage}>
          Load More
        </button>
      )}
    </div>
  )
}

useSearchActors

Search for users:

'use client'

import { useSearchActors } from 'use-bluesky'

export default function SearchPage() {
  const [searchTerm, setSearchTerm] = useState('')
  const { data, isLoading } = useSearchActors({
    search: searchTerm,
    limit: 20,
  })

  return (
    <div>
      <input
        type="text"
        value={searchTerm}
        onChange={(e) => setSearchTerm(e.target.value)}
        placeholder="Search users..."
      />
      {isLoading ? (
        <div>Loading...</div>
      ) : (
        <div>
          {data?.actors.map((actor) => (
            <div key={actor.did}>{actor.displayName}</div>
          ))}
        </div>
      )}
    </div>
  )
}

Additional Hooks

The library also provides these additional hooks:

  • useFollows: Get users that a profile follows
  • useList: Get a list of users
  • useStarterPack: Get a starter pack
  • useActorStarterPacks: Get starter packs for an actor

Each hook is fully typed and integrates with React Query for efficient data fetching and caching.

License

MIT © Ryan Hefner