Last active
March 19, 2019 14:27
-
-
Save ajcrites/2de7832737d6b6abed122062d0d59efb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { useContext } from 'react'; | |
import parse from 'parse-color'; | |
import { ColorAppContext } from '~/ColorApp'; | |
export function useColor() { | |
const { hex, rgba, setHex, setRgba } = useContext(ColorAppContext); | |
const updateHex = hexValue => { | |
const { hex, rgba } = parse(hexValue); | |
setHex(hexValue); | |
setRgba(rgba); | |
}; | |
const updateRgba = rgbaValue => { | |
const { hex, rgba } = parse(rgbaValue); | |
setRgba(rgbaValue); | |
setHex(hex); | |
}; | |
return { hex, rgba, updateHex, updateRgba }; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment