Reactjs TypeError:无法读取属性';需要';未定义的
我是React.js的新手。我试图验证propTypes,但它显示错误“TypeError:无法读取未定义的属性'isRequired'。我将感谢你的建议Reactjs TypeError:无法读取属性';需要';未定义的,reactjs,react-proptypes,Reactjs,React Proptypes,我是React.js的新手。我试图验证propTypes,但它显示错误“TypeError:无法读取未定义的属性'isRequired'。我将感谢你的建议 import React from "react"; import classnames from "classnames"; import PropTypes from "prop-types"; const TextFieldGroup = ({ name, palceholder, value, label, er
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;
从“React”导入React;
从“类名”中导入类名;
从“道具类型”导入道具类型;
常量TextFieldGroup=({
名称
帕切霍尔德,
价值
标签,
错误,
信息,
类型,
一旦改变,
残废
}) => {
返回(
进口应该是这样的
import {PropTypes} from "prop-types";
您确定该错误位于该组件中吗?我有相同的错误,因为:
EmptySearchResults.propTypes = {
searchMessage: PropTypes.message.isRequired
};
因为消息不是propType