Skip to content

Commit 15fc2a1

Browse files
author
Jeppe Reinhold
authored
FIX: Only invoke destroy if it exists
Fixes a bug, where it crashes if `destroy` isn't passed. Adheres to the TypeScript typings, where `destroy` is optional
1 parent 3e3dc66 commit 15fc2a1

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

index.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ module.exports.useAsyncEffect = (effect, destroy, inputs) => {
44
useEffect(() => {
55
let result;
66
effect().then((value) => result = value);
7-
8-
return () => destroy(result);
7+
8+
if(typeof destroy === 'function'){
9+
return () => destroy(result);
10+
}
911
}, inputs);
1012
};

0 commit comments

Comments
 (0)