diff --git a/client/src/pages/Notes/ReactPatterns/ReactNotes/PortalPattern.jsx b/client/src/pages/Notes/ReactPatterns/ReactNotes/PortalPattern.jsx new file mode 100644 index 0000000..f875a6d --- /dev/null +++ b/client/src/pages/Notes/ReactPatterns/ReactNotes/PortalPattern.jsx @@ -0,0 +1,159 @@ +import React from "react"; +import CodeBlock from "../../components/CodeBlock"; + +const PortalPattern = () => { + const examples = [ + { + title: "Basic React Portal", + code: `import React from "react"; +import ReactDOM from "react-dom"; + +function Modal({ children }) { + return ReactDOM.createPortal( +
This is rendered in a portal!
+Modal content rendered using portal.
++ React Portals provide a way to render children into a + DOM node outside of the parent component’s DOM hierarchy. This is + helpful for UI elements like modals, tooltips, and overlays. +
+ ++ Tip: Use portals when + you need components to escape overflow, z-index, or stacking + context issues. +
++ {ex.explanation} +
++ React Portals allow components to render outside their parent + hierarchy, solving overflow and z-index issues. Use them for + modals, tooltips, and overlays for clean and predictable UI + rendering. +
+