Skip to Content
DocumentationHooksuseContrastColor

useContrastColor

The useContrastColor function takes a hex color string as input and returns either #000000 or #ffffff, based on the contrast ratio of the hex color.

Parameters

The function parameter, hex, requires A valid 3 or 6-character hexadecimal color code (e.g. #ABC or #AABBCC).

Usage Example

const textColor = useContrastColor('#37EDDE'); console.log(textColor); // Output: "#000000"
Last updated on