gpt4 book ai didi

reactjs - 类型错误 : Cannot read property 'isRequired' of undefined

转载 作者:行者123 更新时间:2023-12-02 17:00:04 25 4
gpt4 key购买 nike

我是 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com