SHARE
TWEET

Untitled

a guest Mar 23rd, 2019 52 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. };
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top