mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-07 20:31:06 -05:00
d959dbc236
[web] Shared React hooks JS to TS conversion GitOrigin-RevId: 0ccdebff236c7424b1a73cd7d6646a9d01a20eb1
32 lines
616 B
TypeScript
32 lines
616 B
TypeScript
import { useEffect } from 'react'
|
|
import useDetachState, {
|
|
DetachRole,
|
|
DetachTargetRole,
|
|
} from './use-detach-state'
|
|
|
|
type UseDetachParams = Parameters<typeof useDetachState>
|
|
|
|
function useDetachStateWatcher<
|
|
S extends DetachRole,
|
|
T extends DetachTargetRole<S>
|
|
>(
|
|
key: UseDetachParams[0],
|
|
stateValue: UseDetachParams[1],
|
|
senderRole: S,
|
|
targetRole: T
|
|
) {
|
|
const [value, setValue] = useDetachState(
|
|
key,
|
|
stateValue,
|
|
senderRole,
|
|
targetRole
|
|
)
|
|
|
|
useEffect(() => {
|
|
setValue(stateValue)
|
|
}, [setValue, stateValue])
|
|
|
|
return [value, setValue]
|
|
}
|
|
|
|
export default useDetachStateWatcher
|