/
pasha.json
/
react_pro_final_project_base
Обзор
Документация
Войти
/
pasha.json
/
react_pro_final_project_base
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
finalTask
src/shared/api/hooks/useActionCreated.ts
30 строк
885 B
Pavel Nikolaev
tasks 1-5
19 ноя 2025, 17:07
19 ноя 2025, 17:07
804edd8
Код
Авторство
О чём код?
import { ActionCreatorsMapObject, AsyncThunk, bindActionCreators, } from '@reduxjs/toolkit'; import { useMemo } from 'react'; import { useAppDispatch } from '../../store/utils'; export const useActionCreators = <Actions extends ActionCreatorsMapObject>( actions: Actions ): BoundActions<Actions> => { const dispatch = useAppDispatch(); return useMemo( () => bindActionCreators(actions, dispatch), [actions, dispatch] ); }; type BoundActions<Actions extends ActionCreatorsMapObject> = { // eslint-disable-next-line @typescript-eslint/no-explicit-any [key in keyof Actions]: Actions[key] extends AsyncThunk<any, any, any> ? BoundAsyncThunk<Actions[key]> : Actions[key]; }; // eslint-disable-next-line @typescript-eslint/no-explicit-any type BoundAsyncThunk<Thunk extends AsyncThunk<any, any, any>> = ( ...args: Parameters<Thunk> ) => ReturnType<ReturnType<Thunk>>;