Search code examples
javascriptredux-toolkit

Skip arg parameter in createAsyncThunk


I want to skip the first parameter arg of the createAsynchThunk, to access only to the extra parameter to acess the api service I'm sending as extra parameter, is there a way I can skip the arg parameter without using _, undefined or anything like that?

createAsyncThunk(
    'module/fetchModule',
    async (undefined, { extra: api }) => {
        const { data } = await api.get('myendpoint');
        const normalized = normalize(data, [myEntity]);
        return normalized.entities;
    }
);

Solution

  • No, you would need to give it a name. The args are optional for thunks so you don't need to provide anything when calling it.