Skip to content

Commit

Permalink
FIX: Only invoke destroy if it exists
Browse files Browse the repository at this point in the history
Fixes a bug, where it crashes if `destroy` isn't passed. Adheres to the TypeScript typings, where `destroy` is optional
  • Loading branch information
Jeppe Reinhold authored Mar 6, 2019
1 parent 3e3dc66 commit 15fc2a1
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ module.exports.useAsyncEffect = (effect, destroy, inputs) => {
useEffect(() => {
let result;
effect().then((value) => result = value);

return () => destroy(result);

if(typeof destroy === 'function'){
return () => destroy(result);
}
}, inputs);
};

0 comments on commit 15fc2a1

Please sign in to comment.