import isArray from '@tinkoff/utils/is/array' ; import { useMemo } from 'react' ; import { useShallowEqual } from '@tinkoff/react-hooks' ; import type { AnyAction as Action } from '@tramvai/types-actions-state-context' ; import { useConsumerContext } from './useConsumerContext' ; export function useActions < P , R > ( action ) ; export function useActions < A extends Action < any , any > [ ] > ( actions ) ; export function useActions < A extends Readonly < Action < any , any > [ ] > > ( actions ) ; export function useActions ( actions ) { const context = useConsumerContext ( ) ; const actionsRef = useShallowEqual ( actions ) ; return useMemo < any > ( ( ) => { if ( isArray ( actionsRef ) ) { return actionsRef . map ( ( action ) => context . executeAction . bind ( context , action ) ) ; } return context . executeAction . bind ( context , actionsRef ) ; } , [ actionsRef , context ] ) ; }