Skip to content

Commit 1288cb5

Browse files
feat: useLoadData callback functions (#36)
1 parent 9e82008 commit 1288cb5

File tree

9 files changed

+32
-1
lines changed

9 files changed

+32
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
export function complete<T>(onSuccess?: (data: T) => void, onError?: (error: unknown) => void) {
2+
return (err?: unknown, res?: T) => {
3+
if (err) {
4+
onError?.(err);
5+
} else if (res) {
6+
onSuccess?.(res);
7+
}
8+
};
9+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './complete';
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
export function error<T>(onError?: (error: unknown) => void) {
2+
/* eslint-disable @typescript-eslint/no-unused-vars */
3+
return (err?: unknown, res?: T) => {
4+
if (err) {
5+
onError?.(err);
6+
}
7+
};
8+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './error';

hooks/useLoadData/callbacks/index.ts

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export * from './complete';
2+
export * from './error';
3+
export * from './success';
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './success';
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
export function success<T>(onSuccess?: (data: T) => void) {
2+
return (err?: unknown, res?: T) => {
3+
if (res) {
4+
onSuccess?.(res);
5+
}
6+
};
7+
}

hooks/useLoadData/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
export * from './useLoadData';
22
export * from './types';
3+
export * from './callbacks';

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@optum/react-hooks",
3-
"version": "1.0.2",
3+
"version": "1.0.3",
44
"description": "A reusable set of React hooks",
55
"repository": "https://github.com/Optum/react-hooks",
66
"license": "Apache 2.0",

0 commit comments

Comments
 (0)