From 0f02fd093a63dcc6b327a512c4a325d8164fd7ae Mon Sep 17 00:00:00 2001 From: xobotyi Date: Wed, 30 Oct 2019 15:36:02 +0300 Subject: [PATCH] feat(useUpdate): improve memory usage - now single function instance to increment all counters; --- src/useUpdate.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/useUpdate.ts b/src/useUpdate.ts index 495dc04e88..e85142d093 100644 --- a/src/useUpdate.ts +++ b/src/useUpdate.ts @@ -1,10 +1,11 @@ -import { useState, useCallback } from 'react'; +import { useCallback, useState } from 'react'; + +const incrementParameter = (num: number): number => ++num; const useUpdate = () => { const [, setState] = useState(0); // useCallback with empty deps as we only want to define updateCb once - const updateCb = useCallback(() => setState(cnt => cnt + 1), []); - return updateCb; + return useCallback(() => setState(incrementParameter), []); }; export default useUpdate;