gpt4 book ai didi

javascript - 为什么 Form.Select 在我的简单 react-bootstrap 应用程序中没有被识别,遵循 react-bootstrap 文档?

转载 作者:行者123 更新时间:2023-12-05 00:25:07 24 4
gpt4 key购买 nike

我是一个“带钩子(Hook)的 react Bootstrap ”的初学者,我正在创建一个简单的表单。我正在关注 react-bootstrap 文档的示例,但我遇到了选择/选项表单元素的问题。常规文本输入字段正常呈现,没有错误。选择语句似乎把事情搞砸了。
这是我的代码:

import { Form, Button } from "react-bootstrap";

export default function FormComponentName(props) {
return (
<>
<h1>Search Form</h1>

<Form>

<Form.Group className="mb-3" controlId="searchState">
<Form.Label>State</Form.Label>
<Form.Select defaultValue="State...">
<option>State...</option>
<option value="1">One</option>
<option value="2">Two</option>
<option value="3">Three</option>
</Form.Select>
</Form.Group>
<Button variant="primary" type="submit">
Search Data
</Button>

</Form>


</>
)

}

这是 yarn 错误消息:
Error: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined. You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.

Check the render method of `FormComponentName`.

从控制台:
index.js:1 Warning: React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: undefined. You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.

Check your code at FormComponentName.js:14.
at FormComponentName
我需要安装一个额外的模块,还是更明显的?

最佳答案

而不是 Form.Select , 您可以使用:

<Form.Control as="select">...</Form.Control>

关于javascript - 为什么 Form.Select 在我的简单 react-bootstrap 应用程序中没有被识别,遵循 react-bootstrap 文档?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68166687/

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