@patreon/studio
Version:
Patreon Studio Design System
23 lines • 1.04 kB
JSX
'use client';
import React, { useMemo } from 'react';
import { defaultTokensDefinition } from './lib/defaultTokensDefintion';
// Create a context for the token value cache populated with the default tokens definition
const TokenValueCacheContext = React.createContext({
default: defaultTokensDefinition,
});
// Create a hook to access the token value cache context
export const useTokenValueCache = () => React.useContext(TokenValueCacheContext);
export function TokenValueCache({ cacheKey, value, children, }) {
const currentTokenValueCache = useTokenValueCache();
const updatedTokenValueCache = useMemo(() => {
if (cacheKey && value) {
return {
...currentTokenValueCache,
[cacheKey]: value,
};
}
return { ...currentTokenValueCache };
}, [currentTokenValueCache, cacheKey, value]);
return <TokenValueCacheContext.Provider value={updatedTokenValueCache}>{children}</TokenValueCacheContext.Provider>;
}
//# sourceMappingURL=index.jsx.map