Skip to content

Commit

Permalink
feat(viewer): apply useCallback to handleViewportChange, resetViewport
Browse files Browse the repository at this point in the history
  • Loading branch information
LTakhyunKim committed Dec 2, 2022
1 parent 88ca284 commit b2acbf1
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions libs/insight-viewer/src/hooks/useRenewalViewport/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export function useRenewalViewport(
[getDefaultViewport]
)

const resetViewport = () => {
const resetViewport = useCallback(() => {
const defaultViewport = getDefaultViewport()

if (!defaultViewport) {
Expand All @@ -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) => {
Expand Down

0 comments on commit b2acbf1

Please sign in to comment.