From 276c4fc01716a9d065e2acdedfafafb3bb42a3ff Mon Sep 17 00:00:00 2001 From: Leonardo Dino Date: Wed, 27 Feb 2019 14:36:21 -0300 Subject: [PATCH] use array destructuring --- src/use-force-update.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/use-force-update.ts b/src/use-force-update.ts index 2fc6abf..4be6d76 100644 --- a/src/use-force-update.ts +++ b/src/use-force-update.ts @@ -1,13 +1,14 @@ import { useReducer } from 'react'; -type VoidFunction = () => void +type VoidFunction = () => void; type VoidFunctionCreator = () => VoidFunction; type ToggleReducer = (state: boolean, action: void) => boolean; const reducer: ToggleReducer = state => !state; -const useForceUpdate: VoidFunctionCreator = () => ( - useReducer(reducer, true)[1] as VoidFunction -); +const useForceUpdate: VoidFunctionCreator = () => { + const [, dispatch] = useReducer(reducer, true); + return dispatch as VoidFunction; +}; export default useForceUpdate;