首页 > 解决方案 > 使用 Material UI 中的复选框时反应本机的不变违规

问题描述

我正在尝试使用来自 material-ui 的 Checkbox,但我不知道为什么我会收到 Invariant 错误消息

错误:

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

下面是我的代码:

import React from 'react';
import {View,Text,} from 'react-native';
import Checkbox from '@material-ui/core/Checkbox';

export default class App extends React.Component {
  constructor() {
    super();
    this.state = { tick: false };
    this.checkTick = this.checkTick.bind(this);
  }
  checkTick() {
    this.setState({ tick: !this.state.tick });
  }
  render() {
    return (
        <View style={{ alignItems: "center" }}>
          <Text>Hello</Text>
          <View>
            <Checkbox
              checked={this.state.tick}
              onPress={this.checkTick}
              color="primary"
              inputProps={{ 'aria-label': 'secondary checkbox' }}
            />
          </View>
        </View>
    );
  }
};

如果我使用 CheckBox from react-native-elements,那么我不会收到此错误。但我想使用 Material UI 中的 Checkbox

标签: react-native

解决方案


material-ui软件包适用于 ReactJS web,而不适用于 React Native。你不能将此包与 React Native 一起使用。


推荐阅读