首页 > 解决方案 > react-color 库是否在 react-native typescript 中工作

问题描述

我使用 yarn add @types/react-color 添加了包,这是我的组件代码

const ColorPicker: React.FC = () => {
  const [background, setBackground] = useState<string>('#fff');

  const handleChangeComplete = (
    color: ColorResult,
  ) => {
    setBackground(color.hex);
  };
  return (
    <Modal
      animationType="fade"
      transparent
      visible={true}
      presentationStyle="overFullScreen">
      <View
        style={{
          flex: 1,
          alignItems: 'center',
          justifyContent: 'center',
          backgroundColor: 'rgba(0, 0, 0, 0.2)',
        }}>
        <View style={{width: '95%', backgroundColor: '#fff', borderRadius: 7}}>
          <SketchPicker
            color={background}
            onChangeComplete={handleChangeComplete}
          />
        </View>
      </View>
    </Modal>
  );
};

export default ColorPicker;

我有一个按钮,单击时会显示这样的颜色选择器组件

{showPicker && <ColorPicker />}

当我点击按钮时,虽然我看到了这个错误!

Invariant Violation: View config getter callback for component `div` must be a function (received `undefined`). Make sure to start component names with a capital letter.```

标签: typescriptreact-nativecolor-pickerreact-color

解决方案


推荐阅读