mirror of
https://github.com/shlinkio/shlink-web-client.git
synced 2026-03-02 05:36:38 +00:00
Created custom and better typed version of createAsyncThunk
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
import { createAsyncThunk as baseCreateAsyncThunk, AsyncThunkPayloadCreator } from '@reduxjs/toolkit';
|
||||
import { Action } from 'redux';
|
||||
import { ShlinkState } from '../../container/types';
|
||||
|
||||
type ActionHandler<State, AT> = (currentState: State, action: AT) => State;
|
||||
type ActionHandlerMap<State, AT> = Record<string, ActionHandler<State, AT>>;
|
||||
@@ -15,3 +17,8 @@ export const buildReducer = <State, AT extends Action>(map: ActionHandlerMap<Sta
|
||||
};
|
||||
|
||||
export const buildActionCreator = <T extends string>(type: T) => (): Action<T> => ({ type });
|
||||
|
||||
export const createAsyncThunk = <Returned, ThunkArg>(
|
||||
typePrefix: string,
|
||||
payloadCreator: AsyncThunkPayloadCreator<Returned, ThunkArg, { state: ShlinkState }>,
|
||||
) => baseCreateAsyncThunk(typePrefix, payloadCreator);
|
||||
|
||||
Reference in New Issue
Block a user