diff --git a/docs/utils-reference/getting-started.md b/docs/utils-reference/getting-started.md index 5f6e58b..a404c3a 100644 --- a/docs/utils-reference/getting-started.md +++ b/docs/utils-reference/getting-started.md @@ -16,9 +16,13 @@ npm install --save @raycast/utils ## Changelog +### v1.16.5 + +- Fixed the bug where `failureToastOptions` did not apply for `useExec` and `useStreamJSON` hooks. + ### v1.16.4 -- Avoid throwing an error when `useFetch` can't parse the `Content-Type` header of the response +- Avoid throwing an error when `useFetch` can't parse the `Content-Type` header of the response. ### v1.16.3 diff --git a/docs/utils-reference/react-hooks/useAI.md b/docs/utils-reference/react-hooks/useAI.md index 67717d5..caf8073 100644 --- a/docs/utils-reference/react-hooks/useAI.md +++ b/docs/utils-reference/react-hooks/useAI.md @@ -14,7 +14,8 @@ function useAI( execute?: boolean; onError?: (error: Error) => void; onData?: (data: T) => void; - onWillExecute?: (args: string[]) -> void; + onWillExecute?: (args: Parameters) => void; + failureToastOptions?: Partial>; } ): AsyncState & { revalidate: () => void; @@ -37,6 +38,7 @@ Including the [usePromise](./usePromise.md)'s options: - `options.onError` is a function called when an execution fails. By default, it will log the error and show a generic failure toast with an action to retry. - `options.onData` is a function called when an execution succeeds. - `options.onWillExecute` is a function called when an execution will start. +- `options.failureToastOptions` are the options to customize the title, message, and primary action of the failure toast. ### Return diff --git a/docs/utils-reference/react-hooks/useCachedPromise.md b/docs/utils-reference/react-hooks/useCachedPromise.md index d7bad31..b9f82f0 100644 --- a/docs/utils-reference/react-hooks/useCachedPromise.md +++ b/docs/utils-reference/react-hooks/useCachedPromise.md @@ -27,6 +27,7 @@ function useCachedPromise( onError?: (error: Error) => void; onData?: (data: Result) => void; onWillExecute?: (args: Parameters) => void; + failureToastOptions?: Partial>; }, ): AsyncState> & { revalidate: () => void; @@ -54,6 +55,7 @@ Including the [usePromise](./usePromise.md)'s options: - `options.onError` is a function called when an execution fails. By default, it will log the error and show a generic failure toast with an action to retry. - `options.onData` is a function called when an execution succeeds. - `options.onWillExecute` is a function called when an execution will start. +- `options.failureToastOptions` are the options to customize the title, message, and primary action of the failure toast. ### Return diff --git a/docs/utils-reference/react-hooks/useExec.md b/docs/utils-reference/react-hooks/useExec.md index 0d712b8..5af79b1 100644 --- a/docs/utils-reference/react-hooks/useExec.md +++ b/docs/utils-reference/react-hooks/useExec.md @@ -30,7 +30,8 @@ function useExec( execute?: boolean; onError?: (error: Error) => void; onData?: (data: T) => void; - onWillExecute?: (args: string[]) -> void; + onWillExecute?: (args: string[]) => void; + failureToastOptions?: Partial>; } ): AsyncState & { revalidate: () => void; @@ -61,7 +62,8 @@ function useExec( execute?: boolean; onError?: (error: Error) => void; onData?: (data: T) => void; - onWillExecute?: (args: string[]) -> void; + onWillExecute?: (args: string[]) => void; + failureToastOptions?: Partial>; } ): AsyncState & { revalidate: () => void; @@ -110,6 +112,7 @@ Including the [usePromise](./usePromise.md)'s options: - `options.onError` is a function called when an execution fails. By default, it will log the error and show a generic failure toast with an action to retry. - `options.onData` is a function called when an execution succeeds. - `options.onWillExecute` is a function called when an execution will start. +- `options.failureToastOptions` are the options to customize the title, message, and primary action of the failure toast. ### Return diff --git a/docs/utils-reference/react-hooks/useFetch.md b/docs/utils-reference/react-hooks/useFetch.md index 2dbd453..bb96dbd 100644 --- a/docs/utils-reference/react-hooks/useFetch.md +++ b/docs/utils-reference/react-hooks/useFetch.md @@ -20,6 +20,7 @@ export function useFetch( onError?: (error: Error) => void; onData?: (data: T) => void; onWillExecute?: (args: [string, RequestInit]) => void; + failureToastOptions?: Partial>; }, ): AsyncState & { revalidate: () => void; @@ -51,6 +52,7 @@ Including the [usePromise](./usePromise.md)'s options: - `options.onError` is a function called when an execution fails. By default, it will log the error and show a generic failure toast with an action to retry. - `options.onData` is a function called when an execution succeeds. - `options.onWillExecute` is a function called when an execution will start. +- `options.failureToastOptions` are the options to customize the title, message, and primary action of the failure toast. ### Return diff --git a/docs/utils-reference/react-hooks/usePromise.md b/docs/utils-reference/react-hooks/usePromise.md index 9168148..d28cdda 100644 --- a/docs/utils-reference/react-hooks/usePromise.md +++ b/docs/utils-reference/react-hooks/usePromise.md @@ -20,6 +20,7 @@ function usePromise( onError?: (error: Error) => void; onData?: (data: Result) => void; onWillExecute?: (args: Parameters) => void; + failureToastOptions?: Partial>; }, ): AsyncState> & { revalidate: () => void; @@ -39,6 +40,7 @@ With a few options: - `options.onError` is a function called when an execution fails. By default, it will log the error and show a generic failure toast with an action to retry. - `options.onData` is a function called when an execution succeeds. - `options.onWillExecute` is a function called when an execution will start. +- `options.failureToastOptions` are the options to customize the title, message, and primary action of the failure toast. ### Returns diff --git a/docs/utils-reference/react-hooks/useSQL.md b/docs/utils-reference/react-hooks/useSQL.md index a3f62ef..9c8a4f4 100644 --- a/docs/utils-reference/react-hooks/useSQL.md +++ b/docs/utils-reference/react-hooks/useSQL.md @@ -13,7 +13,8 @@ function useSQL( execute?: boolean; onError?: (error: Error) => void; onData?: (data: T) => void; - onWillExecute?: (args: string[]) -> void; + onWillExecute?: (args: string[]) => void; + failureToastOptions?: Partial>; } ): AsyncState & { revalidate: () => void; @@ -37,6 +38,7 @@ Including the [usePromise](./usePromise.md)'s options: - `options.onError` is a function called when an execution fails. By default, it will log the error and show a generic failure toast with an action to retry. - `options.onData` is a function called when an execution succeeds. - `options.onWillExecute` is a function called when an execution will start. +- `options.failureToastOptions` are the options to customize the title, message, and primary action of the failure toast. ### Return diff --git a/docs/utils-reference/react-hooks/useStreamJSON.md b/docs/utils-reference/react-hooks/useStreamJSON.md index 7d57b7c..70564e3 100644 --- a/docs/utils-reference/react-hooks/useStreamJSON.md +++ b/docs/utils-reference/react-hooks/useStreamJSON.md @@ -17,6 +17,7 @@ export function useStreamJSON( onError?: (error: Error) => void; onData?: (data: T) => void; onWillExecute?: (args: [string, RequestInit]) => void; + failureToastOptions?: Partial>; }, ): AsyncState> & { revalidate: () => void; @@ -48,7 +49,8 @@ Including the [usePromise](./usePromise.md)'s options: - `options.execute` is a boolean to indicate whether to actually execute the function or not. This is useful for cases where one of the function's arguments depends on something that might not be available right away (for example, depends on some user inputs). Because React requires every hook to be defined on the render, this flag enables you to define the hook right away but wait until you have all the arguments ready to execute the function. - `options.onError` is a function called when an execution fails. By default, it will log the error and show a generic failure toast with an action to retry. - `options.onData` is a function called when an execution succeeds. -- `options.onWillExecute` is a function called when an execution will start.. +- `options.onWillExecute` is a function called when an execution will start. +- `options.failureToastOptions` are the options to customize the title, message, and primary action of the failure toast. ### Return diff --git a/package.json b/package.json index 3b66e38..3c20444 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@raycast/utils", - "version": "1.16.4", + "version": "1.16.5", "description": "Set of utilities to streamline building Raycast extensions", "author": "Raycast Technologies Ltd.", "homepage": "https://developers.raycast.com/utils-reference", diff --git a/src/useExec.ts b/src/useExec.ts index 6c26ab0..b10b675 100644 --- a/src/useExec.ts +++ b/src/useExec.ts @@ -170,7 +170,7 @@ export function useExec( } & ExecOptions & ExecCachedPromiseOptions, ): UseCachedPromiseReturnType { - const { parseOutput, input, onData, onWillExecute, initialData, execute, keepPreviousData, onError, ...execOptions } = + const { parseOutput, input, onData, onWillExecute, initialData, execute, keepPreviousData, onError, failureToastOptions, ...execOptions } = Array.isArray(optionsOrArgs) ? options || {} : optionsOrArgs || {}; const useCachedPromiseOptions: ExecCachedPromiseOptions = { @@ -180,6 +180,7 @@ export function useExec( onError, onData, onWillExecute, + failureToastOptions, }; const abortable = useRef(); diff --git a/src/useStreamJSON.ts b/src/useStreamJSON.ts index 99c7bc5..8992fa1 100644 --- a/src/useStreamJSON.ts +++ b/src/useStreamJSON.ts @@ -391,6 +391,7 @@ export function useStreamJSON( onError, onData, onWillExecute, + failureToastOptions, dataPath, filter, transform, @@ -407,6 +408,7 @@ export function useStreamJSON( onError, onData, onWillExecute, + failureToastOptions, }; const generatorRef = useRef | null>(null);