diff --git a/hooks/useLoadData/callbacks/complete/complete.ts b/hooks/useLoadData/callbacks/complete/complete.ts new file mode 100644 index 0000000..cd3524e --- /dev/null +++ b/hooks/useLoadData/callbacks/complete/complete.ts @@ -0,0 +1,9 @@ +export function complete(onSuccess?: (data: T) => void, onError?: (error: unknown) => void) { + return (err?: unknown, res?: T) => { + if (err) { + onError?.(err); + } else if (res) { + onSuccess?.(res); + } + }; +} diff --git a/hooks/useLoadData/callbacks/complete/index.ts b/hooks/useLoadData/callbacks/complete/index.ts new file mode 100644 index 0000000..8439abf --- /dev/null +++ b/hooks/useLoadData/callbacks/complete/index.ts @@ -0,0 +1 @@ +export * from './complete'; diff --git a/hooks/useLoadData/callbacks/error/error.ts b/hooks/useLoadData/callbacks/error/error.ts new file mode 100644 index 0000000..e2617f9 --- /dev/null +++ b/hooks/useLoadData/callbacks/error/error.ts @@ -0,0 +1,8 @@ +export function error(onError?: (error: unknown) => void) { + /* eslint-disable @typescript-eslint/no-unused-vars */ + return (err?: unknown, res?: T) => { + if (err) { + onError?.(err); + } + }; +} diff --git a/hooks/useLoadData/callbacks/error/index.ts b/hooks/useLoadData/callbacks/error/index.ts new file mode 100644 index 0000000..93ae819 --- /dev/null +++ b/hooks/useLoadData/callbacks/error/index.ts @@ -0,0 +1 @@ +export * from './error'; diff --git a/hooks/useLoadData/callbacks/index.ts b/hooks/useLoadData/callbacks/index.ts new file mode 100644 index 0000000..1f35eae --- /dev/null +++ b/hooks/useLoadData/callbacks/index.ts @@ -0,0 +1,3 @@ +export * from './complete'; +export * from './error'; +export * from './success'; diff --git a/hooks/useLoadData/callbacks/success/index.ts b/hooks/useLoadData/callbacks/success/index.ts new file mode 100644 index 0000000..ce957b1 --- /dev/null +++ b/hooks/useLoadData/callbacks/success/index.ts @@ -0,0 +1 @@ +export * from './success'; diff --git a/hooks/useLoadData/callbacks/success/success.ts b/hooks/useLoadData/callbacks/success/success.ts new file mode 100644 index 0000000..72aecff --- /dev/null +++ b/hooks/useLoadData/callbacks/success/success.ts @@ -0,0 +1,7 @@ +export function success(onSuccess?: (data: T) => void) { + return (err?: unknown, res?: T) => { + if (res) { + onSuccess?.(res); + } + }; +} diff --git a/hooks/useLoadData/index.ts b/hooks/useLoadData/index.ts index 3c31c3e..512e8b6 100644 --- a/hooks/useLoadData/index.ts +++ b/hooks/useLoadData/index.ts @@ -1,2 +1,3 @@ export * from './useLoadData'; export * from './types'; +export * from './callbacks'; diff --git a/package.json b/package.json index 51044a5..371629c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@optum/react-hooks", - "version": "1.0.2", + "version": "1.0.3", "description": "A reusable set of React hooks", "repository": "https://github.com/Optum/react-hooks", "license": "Apache 2.0",