mirror of
https://github.com/EthanShoeDev/fressh.git
synced 2026-01-11 06:12:51 +00:00
25 lines
703 B
TypeScript
25 lines
703 B
TypeScript
import { QueryClient } from '@tanstack/react-query';
|
|
import { use, type Context } from 'react';
|
|
|
|
export const queryClient = new QueryClient();
|
|
|
|
export type StrictOmit<T, K extends keyof T> = Omit<T, K>;
|
|
|
|
export const AbortSignalTimeout = (timeout: number) => {
|
|
// AbortSignal.timeout is not available as of expo 54
|
|
// TypeError: AbortSignal.timeout is not a function (it is undefined)
|
|
const controller = new AbortController();
|
|
setTimeout(() => {
|
|
controller.abort();
|
|
}, timeout);
|
|
return controller.signal;
|
|
};
|
|
|
|
|
|
export const useContextSafe = <T>(context: Context<T>) => {
|
|
const contextValue = use(context);
|
|
if (!contextValue) {
|
|
throw new Error('Context not found');
|
|
}
|
|
return contextValue;
|
|
}; |