Skip to content

Conversation

@kachar
Copy link
Contributor

@kachar kachar commented Jun 25, 2021

Related to #17

With this update the hook useRealtime accepts both string table name or object { table: string } & UseSelectConfig<Data>

This update is backward compatible so no breaking change is introduced.

Docs are updated with the following example:

import { useRealtime } from 'react-supabase'

function Page() {
  const [result, reexecute] = useRealtime(
    {
      table: 'todos',
      columns: 'id, username, description',
      filter: (query) => query.eq('completed', false),
    },
    (data, payload) => data.username === payload.username,
  )

  return ...
}

@vercel
Copy link

vercel bot commented Jun 25, 2021

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://vercel.com/zoo/react-supabase/FMSb3v7TwKf6bt24qbLkNNQpP1Wx
✅ Preview: https://react-supabase-git-fork-kachar-add-realtime-config-arg-zoo.vercel.app

@kachar
Copy link
Contributor Author

kachar commented Jul 5, 2021

@tmm Any idea why the Size PR check is failing ? It doesn't seem related to the code updates

Comment on lines 33 to 38
export function useRealtime<Data = any>(
table: string,
options: string | ({ table: string } & UseSelectConfig<Data>),
compareFn: UseRealtimeCompareFn<Data> = (a, b) =>
(<CompareFnDefaultData<Data>>a).id ===
(<CompareFnDefaultData<Data>>b).id,
): UseRealtimeResponse<Data> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we keep the table as a string and add a new config parameter?

export type UseRealtimeConfig<Data> = {
    select?: Omit<UseSelectConfig<Data>, 'pause'>
}

export function useRealtime<Data = any>(
    table: string,
    config: UseRealtimeConfig<Data>,
    compareFn: UseRealtimeCompareFn<Data> = (a, b) =>
        (<CompareFnDefaultData<Data>>a).id ===
        (<CompareFnDefaultData<Data>>b).id,
): UseRealtimeResponse<Data>

I appreciate wanting to keep things backward compatible, but it's early enough in the project that I'm fine introducing a breaking change for the sake of a better API foundation for the future.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tmm Code is updated

Indeed this update makes the arguments and the fn api much more explicit and open for extension 🚀

@tmm tmm merged commit aa4cac3 into awkweb:main Jul 6, 2021
@kachar kachar deleted the add-realtime-config-arg branch July 6, 2021 23:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants