Created
June 21, 2021 03:20
-
-
Save ptcampbell/c4c5cee86da0335b66982219eb3d879d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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