Skip to content

Commit

Permalink
use array destructuring
Browse files Browse the repository at this point in the history
  • Loading branch information
leonardodino committed Feb 27, 2019
1 parent ced46c6 commit 276c4fc
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/use-force-update.ts
Original file line number Diff line number Diff line change
@@ -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;

0 comments on commit 276c4fc

Please sign in to comment.