繁体   English   中英

prop-types 在 React Native App 中不起作用

[英]prop-types doesn't work in React Native App

PropTypes 在 React Native 中对我不起作用。 我认为代码很好,但是这样 RN 不会警告我关于 Prop-types 违规和默认道具甚至不起作用,我不知道为什么。

我的 npm 包:“prop-types”:“^15.7.2”,“react”:“16.8.6”,“react-native”:“0.60.4”

import React from "react";
import { Text } from "react-native";
import PropTypes from "prop-types";

import { Modal } from "@ant-design/react-native";

import config from "./config";
import styles from "./styles";

const ModalAlert = ({
  title,
  content,
  okeyCallback,
  cancelCallBack
}) => {
  const renderTitle = title => <Text style={styles.title}>{title}</Text>;

  const renderContent = content => (
    <Text style={styles.content}>{content}</Text>
  );

  const renderBtn = text => <Text style={styles.btn}>{text}</Text>;

  cancelCallBack
    ? Modal.alert(renderTitle(title), renderContent(content), [
        {
          text: renderBtn(config.texts.confirmText),
          onPress: () =>
            okeyCallback === null ? console.log("Ok pressed") : okeyCallback()
        },
        {
          text: renderBtn(config.texts.cancelText),
          onPress: () =>
            cancelCallBack === null
              ? console.log("Cancel pressed")
              : cancelCallBack()
        }
      ])
    : Modal.alert(renderTitle(title), renderContent(content), [
        {
          text: renderBtn(config.texts.confirmText),

          onPress: () =>
            okeyCallback === null ? console.log("Ok pressed") : okeyCallback()
        }
      ]);
};

ModalAlert.PropTypes = {
  title: PropTypes.string.isRequired,
  content: PropTypes.string.isRequired,
  okeyCallback: PropTypes.func,
  cancelCallBack: PropTypes.func
};

ModalAlert.defaultProps = {
  title: "deafult"
};

export { ModalAlert };

应该:

ModalAlert.propTypes = {}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM