Skip to content

Commit

Permalink
feat:#9 ModalPortal util 생성
Browse files Browse the repository at this point in the history
  • Loading branch information
frombozztoang committed Feb 22, 2024
1 parent a38383c commit ef598eb
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/utils/ModalPortal.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
"use client";
import React, { ReactNode, useEffect, useState } from "react";
import ReactDOM from "react-dom";

const ModalPortal: React.FC<{ children: ReactNode }> = ({ children }) => {
const [container, setContainer] = useState<HTMLElement | null>(null);

useEffect(() => {
const el = document.getElementById("modal");
setContainer(el);
}, []);

if (!container) return null;

return ReactDOM.createPortal(children, container);
};

export default ModalPortal;

0 comments on commit ef598eb

Please sign in to comment.