Created
May 16, 2024 07:20
-
-
Save ercnshngit/c5b23048b80ca63b225515324385f3cc to your computer and use it in GitHub Desktop.
Revisions
-
ercnshngit created this gist
May 16, 2024 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,14 @@ import React from 'react' export default function layout({children}) { return ( <html> <body> <PopupManagerContextProvider> {children} </PopupManagerContextProvider> </body> </html> ) } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,14 @@ import React from 'react' export default function Popup({children, name}) { const {openedPopup} = usePopupManager() if(openedPopup !== name) return null return createPortal( <div> {children} </div>, document.body ) } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,12 @@ import React from 'react' export default function OpenPopupButton() { const {setOpenedPopup} = usePopupManager() return ( <button onClick={() => setOpenedPopup('popup1')}> Open Popup </button> ) } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,33 @@ import { createContext, ReactNode, useContext, useState } from "react"; //ekranda 1 tane popup gozukecekse tek yapmak daha mantikli sanki interface PopupManagerProps { openedPopup: string; setOpenedPopup: (popup: string) => void; } export const PopupManagerContext = createContext<PopupManagerProps>({ openedPopup: "", setOpenedPopup: () => {}, }); export const PopupManagerContextProvider = ({ children, }: { children: ReactNode; }) => { const [openedPopup, setOpenedPopup] = useState<string>(""); return ( <PopupManagerContext.Provider value={{ openedPopup, setOpenedPopup, }} > {children} </PopupManagerContext.Provider> ); }; export const usePopupManager = () => useContext(PopupManagerContext);