reactjs - 如何在此处定义 proptypes
问题描述
我无法避免Eslint 错误(“道具类型验证中缺少组件”)。
如何定义proptypes:
- 零件
- 地点
function PrivateRoute({ component: Component, ...rest }) {
return (
<Route
{...rest}
render={props =>
cookies.get("token") !== "" && cookies.get("token") !== undefined ? (
<Component {...props} />
) : (
<Redirect
to={{
pathname: "/401",
state: { from: props.location }
}}
/>
)
}
/>
);
}
PrivateRoute.prototype = {
component: PropTypes.objectOf(React.Component)
};
Redirect.prototype = {
location: PropTypes.string
};
解决方案
你有一些拼写错误,使用prototype
而不是propTypes
:
import PropTypes from 'prop-types';
PrivateRoute.propTypes = {
component: PropTypes.objectOf(React.Component)
};
更多 propTypes 信息在这里
推荐阅读
- javascript - 使用 React 我的 img src 出现问题
- sql - 将sql行转换为单行多列数据
- c# - 为什么引发 PropertyChanged 事件会导致其他控件更新
- php - 返回状态为400时使用phps file_get_contents获取服务器发送的内容
- c - DS1307 RTC 初始化在每次上电时停止工作
- azure-devops - Azure DevOps 中是否有等效的 GitHib 版本?
- terraform - Terraform:创建两个 AWS EC2 实例并从变量传递私有 IP
- java - 如何使用流口水对列表中的元素进行分组
- docker - TensorFlow-serving docker 容器添加了 GPU 设备,但 GPU 的利用率为 0%
- javascript - 未捕获的 CKEditorError:ckeditor-duplicated-modules