Skip to content

Instantly share code, notes, and snippets.

@ajcrites
Last active March 19, 2019 14:27
Show Gist options
  • Save ajcrites/2de7832737d6b6abed122062d0d59efb to your computer and use it in GitHub Desktop.
Save ajcrites/2de7832737d6b6abed122062d0d59efb to your computer and use it in GitHub Desktop.
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