From 15fc2a1155205a02ebadc0e3856213d455d6fb13 Mon Sep 17 00:00:00 2001 From: Jeppe Reinhold Date: Wed, 6 Mar 2019 19:29:06 +0100 Subject: [PATCH] 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 --- index.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index b008866..f25941a 100644 --- a/index.js +++ b/index.js @@ -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); };