代码之家  ›  专栏  ›  技术社区  ›  Ayyoub

commun组件内的图标引发错误

  •  0
  • Ayyoub  · 技术社区  · 7 年前

    我正在尝试建立一个移动应用程序,并使我的代码干净,我决定创建我将经常使用的commun组件。

    我想创建一个验证按钮组件,如下所示:

    import React, { Component } from 'react';
    import PropTypes from 'prop-types';
    import { TouchableOpacity, Text, Icon } from 'react-native';
    import styles from './styles';
    
    /**
     * @export
     * @class ValidateButton
     * @extends {Component}
     */
    export default class ValidateButton extends Component {
        /**
         * default props
         *
         * @static
         * @memberof ValidateButton
         */
        static defaultProps = {
          enabled: true,
        };
    
        /**
         * props validation
         *
         * @static
         * @memberof ValidateButton
         */
        static propTypes = {
          enabled: PropTypes.bool,
          clickHandler: PropTypes.func.isRequired,
          label: PropTypes.string.isRequired,
        };
    
      /**
       * Render the validation button
       *
       * @returns {object}
       * @memberof ValidateButton
       */
        render() {
          return (
            <TouchableOpacity style={styles.footerBoldButton} onPress={this.props.enabled && this.props.clickHandler}>
              <Icon name="check" type="material" color="#FFF" iconStyle={styles.footerBoldButtonIcon} size={16} />
              <Text style={styles.footerBoldButtonText}>{this.props.label}</Text>
            </TouchableOpacity>
          );
        }
    }
    

    我的问题是,当我调用我的组件时,会显示一个错误:

     Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined. You likely forgot to export your component from the file it's defined in.
    

    奇怪的是,当我删除 Icon 它工作的元素。

    有人解释吗?

    1 回复  |  直到 7 年前
        1
  •  0
  •   Ayyoub    7 年前

    我不知道为什么它不适用于 Icon 从…起 react-native 但我可以用 偶像 react-native-elements