Mirror: The highly customizable and versatile GraphQL client with which you add on features like normalized caching as you grow.
at main 583 B view raw
1import type { Client } from '@urql/core'; 2import { createContext, useContext } from 'solid-js'; 3 4export const Context = createContext<Client>(); 5export const Provider = Context.Provider; 6 7export type UseClient = () => Client; 8export const useClient: UseClient = () => { 9 const client = useContext(Context); 10 11 if (process.env.NODE_ENV !== 'production' && client === undefined) { 12 const error = 13 "No client has been specified using urql's Provider. please create a client and add a Provider."; 14 15 console.error(error); 16 throw new Error(error); 17 } 18 19 return client!; 20};