diff --git a/src/hooks/useGlobalCache.tsx b/src/hooks/useGlobalCache.tsx index 93ab6c3..d9a37e7 100644 --- a/src/hooks/useGlobalCache.tsx +++ b/src/hooks/useGlobalCache.tsx @@ -23,7 +23,18 @@ export default function useGlobalCache( ): CacheType { const { cache: globalCache } = React.useContext(StyleContext); const fullPath = [prefix, ...keyPath]; - const fullPathStr = pathKey(fullPath); + + // 缓存fullPathStr,减少render导致的内存占用问题 + const stableFullPathStr = React.useRef(pathKey(fullPath)); + const fullPathStr = React.useMemo(() => { + const _fullPathStr = pathKey(fullPath); + // 比较fullPathStr变更 + if (_fullPathStr !== stableFullPathStr.current) { + stableFullPathStr.current = _fullPathStr; + return _fullPathStr; + } + return stableFullPathStr.current; + }, [fullPath]); const register = useEffectCleanupRegister([fullPathStr]);