MCPcopy Create free account
hub / github.com/LeetCode-OpenSource/ayanami / useAyanamiInstance

Function useAyanamiInstance

src/hooks/use-ayanami-instance.ts:14–33  ·  view source on GitHub ↗
(
  ayanami: M,
  config?: UseAyanamiInstanceConfig<S, U>,
)

Source from the content-addressed store, hash-verified

12export type UseAyanamiInstanceResult<M extends Ayanami<S>, S, U> = [U, ActionMethodOfAyanami<M, S>]
13
14export function useAyanamiInstance<M extends Ayanami<S>, S, U>(
15 ayanami: M,
16 config?: UseAyanamiInstanceConfig<S, U>,
17): UseAyanamiInstanceResult<M, S, U> {
18 const ikari = React.useMemo(() => combineWithIkari(ayanami), [ayanami])
19 const state = useSubscribeAyanamiState(ayanami, config ? config.selector : undefined)
20
21 React.useEffect(
22 () => () => {
23 const isDestroyWhenUnmount = get(config, 'destroyWhenUnmount', false)
24
25 if (isDestroyWhenUnmount) {
26 ayanami.destroy()
27 }
28 },
29 [ayanami, config],
30 )
31
32 return [state, ikari.triggerActions] as UseAyanamiInstanceResult<M, S, U>
33}

Callers 1

useAyanamiFunction · 0.90

Calls 3

combineWithIkariFunction · 0.90
useSubscribeAyanamiStateFunction · 0.90
destroyMethod · 0.80

Tested by

no test coverage detected