Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CREATE MODAL COMPONENT FOR REUSUSABILITY #26

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

Codeprince001
Copy link

While following the course closely, i observed the modal component was copied and duplicated, which is not good way to make code DRY, a component PopupModal.jsx was created and the Modal logic placed in it, while necessary props were passed for functionality...

import React from 'react';
import { HiOutlineExclamationCircle } from "react-icons/hi";
import { Button, Modal } from "flowbite-react";


const PopupModal = ({ onConfirm, showModal, onClose, title }) => {
  return (
    <div>
      <Modal show={showModal} onClose={onClose} popup size="md">
        <Modal.Header />
        <Modal.Body>
          <div className="text-center">
            <HiOutlineExclamationCircle className="text-5xl text-gray-200 dark:text-gray-200 mb-4 mx-auto" />
            <h3 className="mb-5 text-lg text-gray-500 dark:text-gray-400">{title}</h3>
            <div className="flex justify-center gap-4">
              <Button color="failure" onClick={onConfirm}>Yes I'm Sure</Button>
              <Button color="gray" onClick={onClose}>No, Cancel</Button>
            </div>
          </div>
        </Modal.Body>
      </Modal>
    </div>
  );
};

export default PopupModal;

Copying and pasting the modal to different part of the code, eliminate the use of component in React JS, using a reusable Modal across code is more efficient...
Import PopupModal Component to DashPost.jsx and passed Necessary props
Imported PopModal Component to DashProfile.jsx and passed necessary props for customizable render and functionalities.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant