diff --git a/packages/sanity/src/core/releases/hooks/usePerspective.tsx b/packages/sanity/src/core/releases/hooks/usePerspective.tsx index af1778598de..e05b7cf58cd 100644 --- a/packages/sanity/src/core/releases/hooks/usePerspective.tsx +++ b/packages/sanity/src/core/releases/hooks/usePerspective.tsx @@ -72,18 +72,23 @@ export function usePerspective(): PerspectiveValue { : LATEST // TODO: Improve naming; this may not be global. - const currentGlobalBundle = - perspective === 'published' - ? { - _id: 'published', - metadata: { - title: 'Published', - }, - } - : selectedBundle || LATEST - - const setPerspectiveFromRelease = (releaseId: string) => - setPerspective(getBundleIdFromReleaseId(releaseId)) + const currentGlobalBundle = useMemo( + () => + perspective === 'published' + ? { + _id: 'published', + metadata: { + title: 'Published', + }, + } + : selectedBundle || LATEST, + [perspective, selectedBundle], + ) + + const setPerspectiveFromRelease = useCallback( + (releaseId: string) => setPerspective(getBundleIdFromReleaseId(releaseId)), + [setPerspective], + ) const bundlesPerspective = useMemo( () => @@ -123,12 +128,22 @@ export function usePerspective(): PerspectiveValue { [excludedPerspectives], ) - return { - setPerspective, - setPerspectiveFromRelease, - toggleExcludedPerspective, - currentGlobalBundle: currentGlobalBundle, - bundlesPerspective, - isPerspectiveExcluded, - } + return useMemo( + () => ({ + setPerspective, + setPerspectiveFromRelease, + toggleExcludedPerspective, + currentGlobalBundle, + bundlesPerspective, + isPerspectiveExcluded, + }), + [ + bundlesPerspective, + currentGlobalBundle, + isPerspectiveExcluded, + setPerspective, + setPerspectiveFromRelease, + toggleExcludedPerspective, + ], + ) }