( ayanami: M, config?: UseAyanamiInstanceConfig<S, U>, )
| 12 | export type UseAyanamiInstanceResult<M extends Ayanami<S>, S, U> = [U, ActionMethodOfAyanami<M, S>] |
| 13 | |
| 14 | export 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 | } |
no test coverage detected