Skip to content

Instantly share code, notes, and snippets.

@ptcampbell
Created June 21, 2021 03:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ptcampbell/c4c5cee86da0335b66982219eb3d879d to your computer and use it in GitHub Desktop.
Save ptcampbell/c4c5cee86da0335b66982219eb3d879d to your computer and use it in GitHub Desktop.
import { createState, useState } from '@hookstate/core'
import { supabase } from './client'
export type Area = {
id: string
name: string
updated_at: string
data: any
}
export const fetchAreas = async () => {
try {
let { body } = await supabase.from('areas').select(`*`)
return body
} catch (error) {
console.log('error', error)
}
}
const state = createState<Area[]>(
new Promise((resolve) => {
resolve(fetchAreas())
})
)
export function useAreasState() {
return useState(state)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment