All files / src/component/popup Popup.jsx

100% Statements 10/10
100% Branches 4/4
100% Functions 4/4
100% Lines 9/9

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30      3x 69x 69x 16x 1x     16x 16x         69x   16x                      
import React, { useEffect } from 'react';
import "./Popup.css";
 
const Popup = ({ show, onClose, message }) => {
  useEffect(() => {
    if (show) {
      const timer = setTimeout(() => {
        onClose();
      }, 1700);
 
      return () => {
        clearTimeout(timer);
      };
    }
  }, [show, onClose]);
 
  if (!show) return null;
 
  return (
    <div className="popup" style={{ backgroundColor: message.background_color }}>
      <div className="popup-content">
        <h2>{message.title}</h2>
        <p>{message.body}</p>
      </div>
    </div>
  );
};
 
export default Popup;