@patreon/studio
Version:
Patreon Studio Design System
27 lines • 1.19 kB
JavaScript
import { useCallback } from 'react';
import { useCurrentColorScheme } from '../../components/ColorSchemeProvider';
import { useExtractTokenValuePair } from './useExtractTokenValuePair';
/**
* This hook can be used as an escape hatch when you need
* to get the underlying value of a token.
*
* WARNING! This hook is not SSR safe! There is a chance of hydration
* mismatch when the tokenColorMode is selected by the system preferences
* and dark mode is active. In this case the result will be the
* light mode value until the client side hydration occurs.
*
* Consider using useExtractTokenValuePair or useExtractedTokenCss
* where possible to better support SSR.
*
* @deprecated Use `useExtractTokenValuePair` + `useCurrentColorScheme` instead
*/
export function useExtractTokenValue() {
const extractTokenValuePair = useExtractTokenValuePair();
const colorScheme = useCurrentColorScheme();
return useCallback((token) => {
const tokenValuePair = extractTokenValuePair(token);
const tokenValue = tokenValuePair[colorScheme];
return tokenValue;
}, [colorScheme, extractTokenValuePair]);
}
//# sourceMappingURL=useExtractTokenValue.js.map