Skip to content

Instantly share code, notes, and snippets.

@ajcrites
Created March 18, 2019 21:54
Show Gist options
  • Save ajcrites/6de9f59028cb6438fececaa4d9672334 to your computer and use it in GitHub Desktop.
Save ajcrites/6de9f59028cb6438fececaa4d9672334 to your computer and use it in GitHub Desktop.
export const ColorInput = () => {
const { hex, setHex, setRgba } = useContext(ColorToolContext);
const input = useRef(null);
const [show, setShow] = useState(true);
useEffect(() => {
input.current.value = '!';
// input[type=color] is not supported
if ('!' === input.current.value) {
setShow(false);
}
});
const onChange = ({ target: { value } }) => {
setHex(value);
setRgba(value);
};
return show ? (
<label>
Color Picker:
<input type="color" ref={input} value={hex} onChange={onChange} />
</label>
) : null;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment