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

supabase-swr

v1.0.0-alpha.4

Published

A component library to use https://github.com/supabase/supabase-js with https://github.com/vercel/swr

Downloads

6

Readme

supabase-swr

A React library to use supabase-js with swr.

Install

Using npm.

npm install supabase-swr supabase-js swr

Using yarn.

yarn add supabase-swr supabase-js swr

Usage

Crate a supabase client and pass it to the SwrSupabaseContext.Provider.

import { createClient } from 'supabase-js';
import { SwrSupabaseContext } from 'supabase-swr';

const client = createClient('https://xyzcompany.supabase.co', 'public-anon-key');

function App() {
  return (
    <SwrSupabaseContext.Provider value={client}>
      <Routes />
    </SwrSupabaseContext.Provider>  
  )
}

Now you can use in any component the api of supabase-swr.

import React from 'react';
import { useClient, useSelect, useQuery } from 'supabase-swr';

type Todo = {
  id: string,
  name: string,
  created_at: string,
};

const Todos = () => {
  const todosQuery = useQuery<Todo>('todos', {
    filter: (query) => query.order('created_at', { ascending: false }),
  }, []);
  const {
    data: {
      data: todos,
    },
    mutate,
  } = useSelect(todosQuery, {
    // any swr config
    revalidateOnMount: true,
    suspense: true,
  });
  return (
    <ul>
      {todos.map((todo: Todo) => (
        <li key={todo.id}>
          {todo.name}
        </li>
      ))}
    </ul>
  );
}

References

API

hooks

useClient

Retrieve the supabase-js client instance provided to SwrSupabaseContext.Provider.

export default function (props) {
  const client = useClient();
  // ...
  return (<>...</>)
}

useQuery

Create a Query to use with useSelect and other hooks. The created query is also a swr key and can be used with mutate.

type Todo = {}

export default function (props) {
  const query = useQuery<Todo>('todos', {
    // the filter ro apply to the query
    filter: (q) => q.order('created_at', { ascending: false }),
    head: false,
    count: 'exact',
  });
  const {
    data
  } = useSelect(selectKey, {
    // swr config here
  });
  // ...
  return (<></>)
}

useSelect

Retrieve the table data requested. Return and SwrResponse.

type Todo = {}

export default function (props) {
  const query = useQuery<Todo>('todos', {
    // the filter ro apply to the query
    filter: (q) => q.order('created_at', { ascending: false }),
    head: false,
    count: 'exact',
  });
  const {
    data
  } = useSelect(query, {
    // swr config here
  });
  // ...
  return (<></>)
}

useSession

Subscribe to authStateChange event and always return the current session. Useful to use inside component that need to change when the user sign-in or sign-out.

export default function (props) {
  const session = useSession();
  if (!session) return <>Need to sign-in to access this feature</>
  return (<>...</>)
}

createQuery

Create a global Query to use with useSelect and other hooks. The created query is also a swr key and can be used with mutate.

import { useSWRConfig } from 'swr';
import { useState } from 'react';
import { createClient } from 'supabase-js';
import { SwrSupabaseContext, useSelect, createQuery } from 'supabase-swr';

const client = createClient('https://xyzcompany.supabase.co', 'public-anon-key');

type Todo = {
  id: string,
  name: string,
  created_at: string,
}

const todosQuery = createQuery<Todo>('todos', {
  columns: '*',
  // the filter ro apply to the query
  filter: (q) => q.order('created_at', { ascending: false }),
})

function AddTodoForm() {
  const { mutate } = useSWRConfig()
  const client = useClient()
  const [todoName, setTodoName] = useState('')
  const addTodo = () => {
    client.from<Todo>('todos').insert({
      name: todoName,
    }).then(() => {
      // update the todosQuery inside the TodosList
      mutate(todosQuery)
      setTodoName('')
    })
  }
  return (
    <form name="add-todo">
      <input name="todo-name" value={todoName} onChange={(e) => setTodoName(e.target.value)} />
      <button onClick={addTodo}>
        Add Todo
      </button>  
    </form>
  )
}

function TodosList() {
  const {
    data: {
      data: todos,
    },
  } = useSelect(todosQuery, {
    // swr config here
  });
  // ...
  return (
    <ul>
      {todos.map((todo: Todo) => (
        <li key={todo.id}>
          {todo.name}
        </li>
      ))}
    </ul>
  );
}

export default function App() {
  return (
    <SwrSupabaseContext.Provider value={client}>
      <TodosList />
      <AddTodoForm />
    </SwrSupabaseContext.Provider>
  )
}

Inspired by react-supabase.