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 🙏

© 2024 – Pkg Stats / Ryan Hefner

use-supabase

v2.0.1

Published

This is a simple zero dependencies package that gives you access to your Supabase client using a React hook!

Downloads

2,354

Readme

Use Supabase

NPM

A simple package to boost your supabase consumer app.

  // get automatic SWR revalidation on a whole table or a specific column in it
  const { data: siteData } = useTable("site", "*");
  const { data: siteIdData } = useTable("site", "site_id");

  // grab the client to doing anything you want.
  const client = useSupabase();

  // create a query and use all the postgres query options
  const query = useSupabase().from("site").select("*");
  // pass that query to useQuery and get automatic SWR revalidation on it.
  const { data: queryData } = useQuery(query);

Initialize Supabase

To get access to the hooks first pass use the SupabaseContextProvider at the root of your app.

Creat-React-App

import React from 'react'
import ReactDOM from 'react-dom'
import App from './App'
import { SupabaseContextProvider } from 'use-supabase'

import reportWebVitals from './reportWebVitals'
import { createClient } from '@supabase/supabase-js'

const supabase = createClient('supabase-url', 'supabase-anon-key')

ReactDOM.render(
  <React.StrictMode>
    <SupabaseContextProvider client={supabase}>
      <App />
    </SupabaseContextProvider>
  </React.StrictMode>,
  document.getElementById('root')
)

reportWebVitals()

Next.js

If you are using Next.js create a custom _app.tsx like explained here.

Hooks

There are a series of hooks that are made available and usable at your convenience.

useSupabase


useSupabase is the most simple hook in this library. It returns the supabase js client from the context.

  const { auth, from } = useSupabase()

useTable


useTable implements a stale while revalidate strategy. It is a convenient hook to quickly get all information from a table and revalidating the data with the best web performance principles. It will default to getting all the columns on a table but you can pass a select object to specify more details in the query.

const { data } = useTable('users', '*')

useQuery


useQuery gives you the same SWR capacities as useTable but gives you complete granular control on the query you pass.

const query = useSupabase().from('users').select('*').eq(...)
const { data } = useQuery(query)

useUser (deprecated)

useUser gives you access to the supabase client user. While it works in all React applications. If you are using a metaframework like Next.js or Remix, you might prefer to use the supabbase auth helpers.

The context will make avaialble to the hooks the client and the user so that you can use it anywhere along the react component tree.