From a8aed2c38e1b45d3f816b79fdd42bedfc7918319 Mon Sep 17 00:00:00 2001
From: dan <dan.abramov@gmail.com>
Date: Fri, 17 Nov 2023 06:18:37 +0000
Subject: Use non-reactive callbacks for some methods  (#1948)

* Use non-reactive callbacks for some methods

* Remove unnecessary state

* Use non-reactive callbacks for modals
---
 src/state/shell/composer.tsx | 24 +++++++++++++++---------
 1 file changed, 15 insertions(+), 9 deletions(-)

(limited to 'src/state/shell/composer.tsx')

diff --git a/src/state/shell/composer.tsx b/src/state/shell/composer.tsx
index 70d77a7e0..bdf5e4a7a 100644
--- a/src/state/shell/composer.tsx
+++ b/src/state/shell/composer.tsx
@@ -1,5 +1,6 @@
 import React from 'react'
 import {AppBskyEmbedRecord} from '@atproto/api'
+import {useNonReactiveCallback} from '#/lib/hooks/useNonReactiveCallback'
 
 export interface ComposerOptsPostRef {
   uri: string
@@ -47,18 +48,23 @@ const controlsContext = React.createContext<ControlsContext>({
 
 export function Provider({children}: React.PropsWithChildren<{}>) {
   const [state, setState] = React.useState<StateContext>()
+
+  const openComposer = useNonReactiveCallback((opts: ComposerOpts) => {
+    setState(opts)
+  })
+
+  const closeComposer = useNonReactiveCallback(() => {
+    let wasOpen = !!state
+    setState(undefined)
+    return wasOpen
+  })
+
   const api = React.useMemo(
     () => ({
-      openComposer(opts: ComposerOpts) {
-        setState(opts)
-      },
-      closeComposer() {
-        let wasOpen = !!state
-        setState(undefined)
-        return wasOpen
-      },
+      openComposer,
+      closeComposer,
     }),
-    [setState, state],
+    [openComposer, closeComposer],
   )
 
   return (
-- 
cgit 1.4.1

