简体   繁体   English

react-bootstrap 手风琴未加载

[英]react-bootstrap Accordion not loading

I am trying to use react-bootstrap with Bootstrap 5. I want to use Accordion in one of my pages.我正在尝试将 react-bootstrap 与 Bootstrap 5 一起使用。我想在我的一个页面中使用 Accordion。 For that I just copied the structure from this page-> https://react-bootstrap.netlify.app/components/accordion/ .为此,我只是从这个页面复制了结构-> https://react-bootstrap.netlify.app/components/accordion/ But when I open the page, browser shows this error-但是当我打开页面时,浏览器显示此错误-

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 `Questions`.

Here is my code which is using this component这是我使用此组件的代码

import Accordion from 'react-bootstrap/Accordion';

const Questions = () => (
    <Accordion defaultActiveKey="0" flush>
        <Accordion.Item eventKey="0">
            <Accordion.Header>Question #1</Accordion.Header>
            <Accordion.Body>
                Answer to the Question #1
            </Accordion.Body>
        </Accordion.Item>
        <Accordion.Item eventKey="1">
            <Accordion.Header>Question #2</Accordion.Header>
            <Accordion.Body>
                Answer to the Question #2
            </Accordion.Body>
        </Accordion.Item>
    </Accordion>
);


export default Questions;

Other details:其他详情:

  1. "bootstrap": "^5.0.2" “引导程序”:“^5.0.2”
  2. "react": "^17.0.2" “反应”:“^ 17.0.2”
  3. "react-bootstrap":"^1.6.1" “反应引导”:“^ 1.6.1”

Did I miss anything while importing/exporting the component?导入/导出组件时我错过了什么吗? TIA. TIA。

I fixed this problem by replacing react-bootstrap v1.6.1 with the latest v2.0.0beta -> https://www.npmjs.com/package/react-bootstrap/v/2.0.0-beta.0我通过用最新的 v2.0.0beta 替换 react-bootstrap v1.6.1 解决了这个问题 -> https://www.npmjs.com/package/react-bootstrap/v/2.0.0-beta.0

npm uninstall react-bootstrap
npm i react-bootstrap@2.0.0-beta.0

I hope this will solve your problem我希望这能解决你的问题

Reason for the problem问题原因

The problem is that you're using a snippet from the latest v2.0.0 while you have version ^1.6.1 installed.问题是您在安装版本^1.6.1时使用的是latest v2.0.0的片段。

Solution 1解决方案 1

Upgrade the current version of react bootstrap to match the corresponding version for bootstrap.升级当前版本的 react bootstrap 以匹配相应的 bootstrap 版本。 version 2.0.0 Accordion Docs版本2.0.0手风琴文档

npm uninstall react-bootstrap
npm i react-bootstrap@2.2.0

Solution 2方案二

Downgrade the current version of bootstrap to match the corresponding version for react bootstrap and use the snippet from the version 1.6.1 Accordion Docs降级当前版本的 bootstrap 以匹配 react bootstrap 的相应版本,并使用版本1.6.1 Accordion Docs中的代码片段

npm uninstall bootstrap
npm i bootstrap@4.6.0

bootstrap & react-bootstrap compatibility table bootstrap 和 react-bootstrap 兼容性表

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM