···11+import {useCallback, useInsertionEffect, useRef} from 'react'
22+33+// This should be used sparingly. It erases reactivity, i.e. when the inputs
44+// change, the function itself will remain the same. This means that if you
55+// use this at a higher level of your tree, and then some state you read in it
66+// changes, there is no mechanism for anything below in the tree to "react"
77+// to this change (e.g. by knowing to call your function again).
88+//
99+// Also, you should avoid calling the returned function during rendering
1010+// since the values captured by it are going to lag behind.
1111+export function useNonReactiveCallback<T extends Function>(fn: T): T {
1212+ const ref = useRef(fn)
1313+ useInsertionEffect(() => {
1414+ ref.current = fn
1515+ }, [fn])
1616+ return useCallback(
1717+ (...args: any) => {
1818+ const latestFn = ref.current
1919+ return latestFn(...args)
2020+ },
2121+ [ref],
2222+ ) as unknown as T
2323+}
+10-6
src/view/com/modals/Modal.tsx
···99import once from 'lodash.once'
10101111import {useModals, useModalControls} from '#/state/modals'
1212+import {useNonReactiveCallback} from '#/lib/hooks/useNonReactiveCallback'
1213import * as ConfirmModal from './Confirm'
1314import * as EditProfileModal from './EditProfile'
1415import * as ProfilePreviewModal from './ProfilePreview'
···50515152 const navigateOnce = once(navigate)
52535353- const onBottomSheetAnimate = (_fromIndex: number, toIndex: number) => {
5454- if (activeModal?.name === 'profile-preview' && toIndex === 1) {
5555- // begin loading the profile screen behind the scenes
5656- navigateOnce('Profile', {name: activeModal.did})
5757- }
5858- }
5454+ // It seems like the bottom sheet bugs out when this callback changes.
5555+ const onBottomSheetAnimate = useNonReactiveCallback(
5656+ (_fromIndex: number, toIndex: number) => {
5757+ if (activeModal?.name === 'profile-preview' && toIndex === 1) {
5858+ // begin loading the profile screen behind the scenes
5959+ navigateOnce('Profile', {name: activeModal.did})
6060+ }
6161+ },
6262+ )
5963 const onBottomSheetChange = async (snapPoint: number) => {
6064 if (snapPoint === -1) {
6165 closeModal()