forked from
jollywhoppers.com/witchsky.app
Bluesky app fork with some witchin' additions 馃挮
1import {useInsertionEffect, useRef} from 'react'
2
3/**
4 * This should be used sparingly. It erases reactivity, i.e. when the inputs
5 * change, the returned object itself will remain the same. This means that if
6 * you use this at a higher level of your tree, and then some state you read in
7 * it changes, there is no mechanism for anything below in the tree to "react"
8 * to this change (e.g. by knowing to call your function again).
9 *
10 * For callbacks, see `useNonReactiveCallback` instead.
11 */
12export function useNonReactiveObject<T extends Record<string, unknown>>(
13 o: T,
14): React.RefObject<T> {
15 const ref = useRef(o)
16 useInsertionEffect(() => {
17 ref.current = o
18 }, [o])
19 return ref
20}