如何设置一个React-Flowbite模态框?

huangapple go评论90阅读模式
英文:

How to setup a react-flowbite modal?

问题

While adding the react-flowbite modal to a react code, this error appears:

如何设置一个React-Flowbite模态框?

How to configure all that? How to setup a button so that it toggles the modal onClick?
Thanks

These are the imports:

import {
  Button,
  Checkbox,
  Label,
  Modal,
  TextInput,
} from "flowbite-react";

This is the code:
(Couldn't paste it here because the code was more than text)
<https://flowbite-react.com/modal>

Scroll down up to "form elements"

英文:

While adding the react-flowbite modal to a react code, this error appears:

如何设置一个React-Flowbite模态框?

How to configure all that? How to setup a button so that it toggles the modal onClick?
Thanks

These are the imports :

import {
  Button,
  Checkbox,
  Label,
  Modal,
  TextInput,
} from &quot;flowbite-react&quot;;

This is the code:
(Couldn't paste it here because the code was more that text)
<https://flowbite-react.com/modal>

Scroll down up to "form elements"

答案1

得分: 0

使用导入的 Modal 作为您的 Modal 组件的包装器

import { Modal } from "flowbite-react";
function App() {
  const [show, setShow] = useState(false);
  return (
    <button onClick={() => setShow(true)}>切换模态框</button>
    <Modal show={show} handleClose={() => setShow(false)}>
      <div>模态框内容</div>
    </Modal>
  );
}
英文:

use imported Modal as wrapper for your Modal component

import { Modal } from &quot;flowbite-react&quot;;
function App() {
const [show, setShow] = useState(false)
return (
&lt;button onClick={() =&gt; setShow(true)}&gt;toggle modal&lt;/button&gt;
&lt;Modal show={show} handleClose={() =&gt; setShow(false)}&gt;
&lt;div&gt;Modal Content&lt;/div&gt;
&lt;/Modal&gt;
)
}

huangapple
  • 本文由 发表于 2023年5月7日 11:41:00
  • 转载请务必保留本文链接:https://go.coder-hub.com/76192096.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定