reactjs - 'render' 在 React 中没有被定义为 no-undef
问题描述
我已经制作了组件。我将在我的组件中使用 forms-validation(react-bootstrap)。当我在组件中制作此表单时,出现如下错误:
'render' 未定义 no-undef'
代码:
import react, {Component} from 'react';
export defaults class Test extends Component {
constructor(props) {
super(props)
this.state = {....}
}
render() {
return(
<div></div>
)
}
}
function FormExample() {
const [validated, setValidated] = useState(false);
const handleSubmit = (event) => {
const form = event.currentTarget;
if (form.checkValidity() === false) {
event.preventDefault();
event.stopPropagation();
}
setValidated(true);
};
return(
<Form noValidate validated={validated} onSubmit={handleSubmit}>
....
</Form>
);
render(<FormExample />);
}
https://react-bootstrap.github.io/components/forms/#forms-validation
这是我使用的表单验证。
请提出任何建议:
解决方案
你已经用过functional component
和没用过function,FormExample
支持function 。使用与渲染类似的 return 语句。所以请从.functional component
render
class component
render
Functional component
FormExample
render(<FormExample />);
这是删除渲染后的代码:
function FormExample() {
const [validated, setValidated] = useState(false);
const handleSubmit = (event) => {
const form = event.currentTarget;
if (form.checkValidity() === false) {
event.preventDefault();
event.stopPropagation();
}
setValidated(true);
};
return(
<Form noValidate validated={validated} onSubmit={handleSubmit}>
....
</Form>
);
}
推荐阅读
- node.js - 未找到模块:错误:将 nodejs 版本更新为 10.0 后无法解析“firebase”
- java - 如何添加到 BorderLayout.Center?
- api - 使用 API 时在关闭收集器时删除 SurveyMonkey 品牌?
- reactjs - ReactJS Route 不同的布局
- javascript - 如何根据gridview中文件夹中的特定文件名在gridview中显示文件
- python-2.7 - Aws Boto3 客户端(低级)与资源(高级)
- javascript - 如何在时刻 js 中将纪元时间戳转换为带有时区的日期时间?
- sms - Twilio 我们可以添加 ID 来区分来自同一号码的消息吗?
- c# - N用不明确的参数替换数组?
- php - 使用php用空格替换以空格分隔的2个逗号