MCPcopy
hub / github.com/NervJS/nerv / useImperativeHandle

Function useImperativeHandle

packages/nerv/src/hooks.ts:217–233  ·  view source on GitHub ↗
(
  ref: RefObject<T> | undefined,
  init: () => R,
  deps?: DependencyList
)

Source from the content-addressed store, hash-verified

215}
216
217export function useImperativeHandle<T, R extends T> (
218 ref: RefObject<T> | undefined,
219 init: () => R,
220 deps?: DependencyList
221): void {
222 useLayoutEffect(() => {
223 if (isFunction(ref)) {
224 ref(init())
225 return () => ref(null)
226 } else if (!isUndefined(ref)) {
227 ref.current = init()
228 return () => {
229 delete ref.current
230 }
231 }
232 }, isArray(deps) ? deps.concat([ref]) : undefined)
233}

Callers

nothing calls this directly

Calls 3

isFunctionFunction · 0.90
isUndefinedFunction · 0.90
useLayoutEffectFunction · 0.85

Tested by

no test coverage detected