react-native-global-state-hooks
Version:
This is a package to easily handling global-state across your react-native-components No-redux... The library now includes @react-native-async-storage/async-storage to persist your state across sessions... if you want to keep using the old version without
20 lines (19 loc) • 930 B
TypeScript
type TryCatchResult<T extends (...args: any) => any, Fallback extends ReturnType<T> | undefined> = T extends () => Promise<infer R> ? Promise<{
result: Fallback extends undefined ? R | null : NonNullable<R>;
error: any;
}> : {
result: Fallback extends undefined ? ReturnType<T> | null : NonNullable<ReturnType<T>>;
error: any;
};
/**
* Lineal try/catch function.
*
* If the callback is synchronous, it returns an object: `{ result, error }`.
* If the callback returns a promise, it returns a promise that resolves to: `{ result, error }`.
*
* @template T
* @param {() => T | Promise<T>} callback - The function to execute.
* @returns {{ result: T | null, error: any } | Promise<{ result: T | null, error: any }>}
*/
declare function tryCatch<T extends () => any, Fallback extends Awaited<ReturnType<T>> | undefined>(callback: T, fallback?: Fallback): TryCatchResult<T, Fallback>;
export default tryCatch;