From 181e61bedb21003921fa21f6e8b86baf918d62bf Mon Sep 17 00:00:00 2001
From: dan <dan.abramov@gmail.com>
Date: Wed, 1 May 2024 05:35:52 +0100
Subject: Memoize context value (#3786)

---
 src/components/Portal.tsx | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)

(limited to 'src/components/Portal.tsx')

diff --git a/src/components/Portal.tsx b/src/components/Portal.tsx
index d696f986b..03b397b2b 100644
--- a/src/components/Portal.tsx
+++ b/src/components/Portal.tsx
@@ -34,10 +34,17 @@ export function createPortalGroup() {
       setOutlet(<>{Object.values(map.current)}</>)
     }, [])
 
+    const contextValue = React.useMemo(
+      () => ({
+        outlet,
+        append,
+        remove,
+      }),
+      [outlet, append, remove],
+    )
+
     return (
-      <Context.Provider value={{outlet, append, remove}}>
-        {props.children}
-      </Context.Provider>
+      <Context.Provider value={contextValue}>{props.children}</Context.Provider>
     )
   }
 
-- 
cgit 1.4.1

