Advertisement
Guest User

Untitled

a guest
Mar 23rd, 2019
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.57 KB | None | 0 0
  1. export const ColorInput = () => {
  2. const { hex, setHex, setRgba } = useContext(ColorToolContext);
  3. const input = useRef(null);
  4.  
  5. const [show, setShow] = useState(true);
  6.  
  7. useEffect(() => {
  8. input.current.value = '!';
  9. // input[type=color] is not supported
  10. if ('!' === input.current.value) {
  11. setShow(false);
  12. }
  13. });
  14.  
  15. const onChange = ({ target: { value } }) => {
  16. setHex(value);
  17. setRgba(value);
  18. };
  19.  
  20. return show ? (
  21. <label>
  22. Color Picker:
  23. <input type="color" ref={input} value={hex} onChange={onChange} />
  24. </label>
  25. ) : null;
  26. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement