- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我是 React.js 的新手。我正在尝试验证 propTypes,但它显示错误“TypeError:无法读取未定义的属性‘isRequired’”。我将感谢您的建议。
import React from "react";
import classnames from "classnames";
import PropTypes from "prop-types";
const TextFieldGroup = ({
name,
palceholder,
value,
label,
error,
info,
type,
onChange,
disabled
}) => {
return (
<div className="form-group">
<input
type={type}
className={classnames("form-control form-control-lg", {
"is-invalid": { error }
{error && <div className="invalid-feedback">{error}</div>}
</div>
);
};
TextFieldGroup.propTypes = {
name: PropTypes.string.isRequired,
palceholder: PropTypes.string,
value: PropTypes.string.isRequired,
label: PropTypes.string,
error: PropTypes.string,
info: PropTypes.string,
type: PropTypes.string.isRequired,
onChange: PropTypes.func.isRequired,
disabled: PropTypes.string
};
TextFieldGroup.defaultProps = {
type: "text"
};
export default TextFieldGroup;
最佳答案
导入应该是这样的
import {PropTypes} from "prop-types";
关于reactjs - 类型错误 : Cannot read property 'isRequired' of undefined,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54543831/
我有一个组件需要 propType oneOfType bool 或 object 所以我写道: processInfoValues: PropTypes.oneOfType([ PropTyp
我遇到了这个奇怪的问题...在我的代码中,无论我将 IsRequired 的值设置为 false 还是 true,它都会保持为 false。但是,如果我输入 DefaultValue,它会起作用吗?
我正在创建一个包含两个 Prop 的组件。第一个是字符串列表,例如['string1', 'string2'] 第二个是字符串列表,例如[['string1arr1' ,'string2arr1'],
我有一个契约(Contract)如下: [DataContract] public class MyObj { [DataMember(IsRequired=true)] public
Protobuf-Net ProtoMember“IsRequired”属性的用途是什么? 如果我向文件中已序列化的类添加新属性(成员),会产生什么影响。如果我使用“IsRequired=true”,
假设我定义了这个 PropType: Component.propTypes = { complicatedData: PropTypes.arrayOf( PropTypes.shape
我有一个要序列化的类 [System.Xml.Serialization.XmlTypeAttribute(Namespace = "http://xyz.com/schema")] public c
我有一个简单的模型: public class Sample { public bool A { get; set; } [Required] public bool B {
我们可以有一个不允许空值的必需 XmlAttribute 吗?我想在 XmlAttribute 中使用 IsRequired = true 之类的东西。可以吗?我知道 XmlAttribute 有一个
我是 React 的新手,正在尝试定义 PropTypes,但它似乎不再有效了: 下面是我是如何使用它的: React.PropTypes.func.isRequired 下面是我得到的错误: 那么这
在以前的版本为EF5和EF4的项目中,如果属性为null或空字符串,则IsRequired()流利的API方法将引发DbEntityValidationException。在我当前使用EF6的项目中,
问题 如果我有一个特定实体的属性数组并且我正在遍历它们,有什么方法可以检查我在每个循环中迭代的反射类型属性是否配置为 。 IsRequired() 在其对应的实体上? 示例 这个问题必须特别针对 st
我是 React.js 的新手。我正在尝试验证 propTypes,但它显示错误“TypeError:无法读取未定义的属性‘isRequired’”。我将感谢您的建议。 import React fr
我是 React.js 的新手。我正在尝试验证 propTypes,但它显示错误“TypeError:无法读取未定义的属性‘isRequired’”。我将感谢您的建议。 import React fr
我有一个实体属性定义如下 public virtual string Subject { get; set; } 及其映射为 this.Property(t => t.Subject)
我今天在 WCF 契约(Contract)中遇到了这个: [DataMember(IsRequired = true)] public DateTime? LastModified { get; se
我对 react (或者说网络技术)很陌生。我开始构建一个使用不同组件的应用程序。当我浏览文档时,我认为将 isRequired 放在 propTypes 中,会强制用户在使用组件时提供所有 isRe
我有以下组件: import React from 'react' import PropTypes from 'prop-types' const MyComponent = ({ text1, t
我注意到 React 组件有一个 type.propTypes 对象,它将所有 propTypes 作为键。 例如, Component.propTypes = { initialCount: Rea
我正在尝试学习 React,但 PropTypes 即使与 isRequired 一起使用也不会引发任何错误。我是不是做错了什么。 代码是这样的 function SayHello
我是一名优秀的程序员,十分优秀!