javascript - prop-types 在 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 = {}
推荐阅读
- ruby-on-rails - Ruby on Rails 零值
- sql - 在 SQL Server 表中将一行拆分为多行
- java - Spring 和 MongoDB 异步 Java 驱动程序 - clusterListener 不能为空
- android - android studio 模拟器停止了我的应用程序
- c# - 亚马逊 AWS Cognito 身份登录 Xamarin 中的 IdentityNotFound 错误
- python - 无法让 twiny() 在直方图中正确对齐 X 轴
- pytorch - 非标准化 PyTorch 数据
- mysql - 使用 CTE 在 mysql 中排名()
- r - Tidyr 单独返回错误“_tidyr_simplifyPieces”
- string - 在 Python 中的另一行上放置一块分割线?