Home > OS >  Use modal component in reactjs
Use modal component in reactjs

Time:10-22

I install antd library from its site and import modal component from it but it is not working for me . I checked everything and was fine . I don't know where problem is .this is summary of my code

import { Button, Modal } from 'antd';
 
 const [isModalOpen, setIsModalOpen] = React.useState(false);
  console.log(isModalOpen)
  const showModal = () => {
    setIsModalOpen(true);
   };
  const handleOk = () => {
    setIsModalOpen(false);
  };
  const handleCancel = () => {
    setIsModalOpen(false);
  };
  return (
  <>
  <Button type="primary" onClick={showModal}>
        Open Modal
      </Button>
      <Modal title="Basic Modal" open={isModalOpen} onOk={handleOk} onCancel={handleCancel}>
        <p>Some contents...</p>
        <p>Some contents...</p>
        <p>Some contents...</p>
      </Modal>
    </>

CodePudding user response:

Please check you antd version. If you are using v3, please try

visible={isModalOpen}

Update: Don't forget to add import 'antd/dist/antd.css'; inside App.js for index.js to apply the style

  • Related