yuanfux / react-native-hsv-color-picker

a react native HSV(hue, saturation, value) color picker
https://snack.expo.io/@fuyuanx/react-native-hsv-color-picker
48 stars 41 forks source link

Cannot read property 'getCurrentColor' of null. #3

Closed chrisehlee closed 5 years ago

chrisehlee commented 5 years ago

I have a react native screen in which i'm using the useRef() hook to set a ref for the HsvColorPicker .. however, i can't access the getCurrentColor() method of it as i get a

TyperError: Cannot read property 'getCurrentColor' of null
...
yuanfux commented 5 years ago

Please try the following syntax and make sure you have hook-supported react(> 16.8) & react native(> 0.59) versions installed . I'll close this issue for now. If you have any further concerns or questions, feel free to reopen this issue.

function test() {
  const hsvColorPicker = useRef(null);
  const getColor = () => {
    console.log(hsvColorPicker.current.getCurrentColor());
  };
  return (
    <>
      <HsvColorPicker
         ref={hsvColorPicker}
         // more props...
      />
      <TouchableOpacity onPress={getColor}>
         <Text>Get Current Color</Text>
      </TouchableOpacity>
    </>
  );
}