From b2acbf16bf977abee84499aae184021cae2a64f8 Mon Sep 17 00:00:00 2001 From: Takhyun Kim Date: Fri, 2 Dec 2022 17:51:26 +0900 Subject: [PATCH] feat(viewer): apply useCallback to handleViewportChange, resetViewport --- .../src/hooks/useRenewalViewport/index.ts | 22 +++++++++++-------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/libs/insight-viewer/src/hooks/useRenewalViewport/index.ts b/libs/insight-viewer/src/hooks/useRenewalViewport/index.ts index 2112a44ab..c6779c56c 100644 --- a/libs/insight-viewer/src/hooks/useRenewalViewport/index.ts +++ b/libs/insight-viewer/src/hooks/useRenewalViewport/index.ts @@ -56,7 +56,7 @@ export function useRenewalViewport( [getDefaultViewport] ) - const resetViewport = () => { + const resetViewport = useCallback(() => { const defaultViewport = getDefaultViewport() if (!defaultViewport) { @@ -83,22 +83,26 @@ export function useRenewalViewport( } else { setViewport({ ...defaultViewport, _viewportOptions: options }) } - } + }, [getDefaultViewport, getInitialViewport, options]) /** * We assigned the function type and the value type * for the immediate viewport assignment as union type * to utilize the previous viewport. */ - const handleViewportChange = (setViewportAction: SetViewportAction) => { - setViewport((prevViewport) => { - const newViewport = typeof setViewportAction === 'function' ? setViewportAction(prevViewport) : setViewportAction + const handleViewportChange = useCallback( + (setViewportAction: SetViewportAction) => { + setViewport((prevViewport) => { + const newViewport = + typeof setViewportAction === 'function' ? setViewportAction(prevViewport) : setViewportAction - const updatedViewport = getViewportWithFitScaleOption(newViewport, options.fitScale) + const updatedViewport = getViewportWithFitScaleOption(newViewport, options.fitScale) - return updatedViewport - }) - } + return updatedViewport + }) + }, + [getViewportWithFitScaleOption, options.fitScale] + ) useEffect(() => { setViewport((prevViewport) => {