Code Monkey home page Code Monkey logo

react-supabase's Introduction

Introduction

react-supabase is a React Hooks library for Supabase.

Visit the docs site for more info.


Installation

yarn add react-supabase @supabase/supabase-js
# or
npm install --save react-supabase @supabase/supabase-js

Quick Start

Create a Supabase client and pass it to the Provider:

import { createClient } from '@supabase/supabase-js'
import { Provider } from 'react-supabase'

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

const App = () => (
  <Provider value={client}>
    <YourRoutes />
  </Provider>
)

Now every component inside and under the Provider can use the Supabase client and hooks:

import { useRealtime } from 'react-supabase'

const Todos = () => {
  const [result, reexecute] = useRealtime('todos')

  const { data, fetching, error } = result

  if (fetching) return <p>Loading...</p>
  if (error) return <p>Oh no... {error.message}</p>

  return (
    <ul>
      {data.map((todo) => (
        <li key={todo.id}>{todo.title}</li>
      ))}
    </ul>
  )
}

License

The MIT License.

react-supabase's People

Contributors

ao-barbosa avatar bruceharrison1984 avatar dependabot[bot] avatar kachar avatar tmm avatar y-yagi avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

react-supabase's Issues

Recursive execution of real-time hook when filter option is passed.

Bug report

Description / Observed Behavior

Recursive execution of real-time hook when filter option is passed.

Expected Behavior

Open a websocket connection and subscribe to changes

Repro Steps / Code Example

const Chats: React.FC<ITabsProps<'Chats'>> = ({}) => {
  const [{ data }] = useRealtime<DB.Member>(
    'members',
    {
      select: {
        columns: 'id',
        filter: (query) => query.eq('userId', '94a9aa95-c794-404a-9a37-7f424b215ebb'), // Works when this line is removed
      },
    }
  )

  useEffect(() => console.log(data), [data])

  return (...)
}

Additional Context

{
    "@supabase/supabase-js": "^1.24.0",
    "expo": "~42.0.1",
    "react": "16.13.1",
    "react-dom": "16.13.1",
    "react-native": "https://github.com/expo/react-native/archive/sdk-42.0.0.tar.gz",
    "react-supabase": "^0.2.0"
  }

This might be a fault of mine. I can't read the HTTP request or console logs as Firefox just breaks when I execute this.

Promises never reject - exceptions are swallowed

Bug report

Description / Observed Behavior

Use something like useInsert and force an error (insert null value in required column). Either wrap the call in a try/catch block, or utilize the .catch syntax for callbacks. The catch block never hits. The exception is swallowed, and returned in the errors property instead. This is not the behavior I would expect, because any libraries that can be used with promises (react-toastify in my case) cannot be directly used with this library.

Expected Behavior

I would expect exceptions to propagate up as they traditionally do, or provide some means to opt-out of this behavior.

Repro Steps / Code Example

const [_, insertEvent] = useInsert<CalendarEvent>('calendar_event');

try {
  const insertFunc = await insertEvent({
    // insert nothing to force a validation error
  })
  } catch (err) {
    console.log(err) //<-- this will never be hit
  }

  const insertFunc = await insertEvent({
    // insert nothing to force a validation error
  }).catch(error => {
    console.log(error); // <-- this will never be hit
  });

Additional Context

The issue can be worked around by wrapping the call

  const insertFunc = async () => {
    const { data, count, error } = await insertEvent({
      // force error
    })
    if (error) throw error;
    return { data, count };
  }

This could be made suitably generic to wrap any call, but feels like this shouldn't be necessary.

ERROR Unhandled promise rejection [RangeError: Maximum call stack size exceeded (native stack depth)]

Bug report

Whenever I include the provider in my Expo app I get:

 ERROR  Unhandled promise rejection [RangeError: Maximum call stack size exceeded (native stack depth)]

Description / Observed Behavior

 ERROR  Unhandled promise rejection [RangeError: Maximum call stack size exceeded (native stack depth)]

Expected Behavior

No errors

Repro Steps / Code Example

Additional Context

latest supabase js and react-supabase

useAuthStateChange fails in @supabase/supabase-js v2+

Bug report

useAuthStateChange fails in @supabase/supabase-js v2+

Description / Observed Behavior

The useAuthStateChange hook throws a n.unsubscribe is not a function error on v2 versions of supabase/supabase-js.

Expected Behavior

Hook does not throw page breaking error and returns documented values.

Repro Steps / Code Example

https://codesandbox.io/s/sharp-snow-vdzivd?file=/src/App.tsx:311-312

Additional Context

react-supabase version - 0.2.0
@supabase/supabase-js - 2.2.3

The authStateChanged listener has since been updated to return a subscription object with the unsubscribe function.

I guess this is a question of compatibility since this library is only rated for v1 but are there plans for v2 support and or are PRs updating the existing hooks welcome?

useRealtime does not work with foreign values

Bug report

Description / Observed Behavior

I am using the useRealtime functionality like this:

const [{ data: payments, error, fetching }] = useRealtime(
         "payments",
        {
            select: {
                columns: 'id, created_at, amountToPay, user (userId, displayName, email)',
                filter: (query) => query.eq("state", OPEN)
            }
        },
        (data, payload) => data.id === payload.id);

The problem I am facing is, that after an update occurs with the given query and filters, I can not get the user.

Expected Behavior

Just like fetching, when the data is updated, I recieve the complete row with foreign relations updated.
I would expect, that when in the code above the amountToPay changes, that I recieve the whole updated row with the foreign relationship of user with it.

`useSignIn()` with Google OAuth creates account but hook does not work

Bug report

The useSignIn() hook does not work correctly.

Description / Observed Behavior

Try to use the sign-in hook, and successfully log in (the user is created in the Supabase console), but when I'm redirected, the new session is not loaded by the hook, despite that being the core functionality:

const [{ error, fetching, session, user }, signIn] = useSignIn();
console.log({ user, session });
// { user: undefined, session: undefined }

Expected Behavior

After signing in, the hook should return the user and session data.

const [{ error, fetching, session, user }, signIn] = useSignIn();
console.log({ user, session });
// something other than all undefined

Repro Steps / Code Example

Included.

Additional Context

Latest version. Basic sign-in. No idea why this would not work out of the box.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.