Skip to content

Commit

Permalink
feat: useLoadData callback functions (#36)
Browse files Browse the repository at this point in the history
  • Loading branch information
NielsJPeschel authored May 15, 2024
1 parent 9e82008 commit 1288cb5
Show file tree
Hide file tree
Showing 9 changed files with 32 additions and 1 deletion.
9 changes: 9 additions & 0 deletions hooks/useLoadData/callbacks/complete/complete.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export function complete<T>(onSuccess?: (data: T) => void, onError?: (error: unknown) => void) {
return (err?: unknown, res?: T) => {
if (err) {
onError?.(err);
} else if (res) {
onSuccess?.(res);
}
};
}
1 change: 1 addition & 0 deletions hooks/useLoadData/callbacks/complete/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './complete';
8 changes: 8 additions & 0 deletions hooks/useLoadData/callbacks/error/error.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export function error<T>(onError?: (error: unknown) => void) {
/* eslint-disable @typescript-eslint/no-unused-vars */
return (err?: unknown, res?: T) => {
if (err) {
onError?.(err);
}
};
}
1 change: 1 addition & 0 deletions hooks/useLoadData/callbacks/error/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './error';
3 changes: 3 additions & 0 deletions hooks/useLoadData/callbacks/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export * from './complete';
export * from './error';
export * from './success';
1 change: 1 addition & 0 deletions hooks/useLoadData/callbacks/success/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './success';
7 changes: 7 additions & 0 deletions hooks/useLoadData/callbacks/success/success.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export function success<T>(onSuccess?: (data: T) => void) {
return (err?: unknown, res?: T) => {
if (res) {
onSuccess?.(res);
}
};
}
1 change: 1 addition & 0 deletions hooks/useLoadData/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export * from './useLoadData';
export * from './types';
export * from './callbacks';
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down

0 comments on commit 1288cb5

Please sign in to comment.