Skip to content

createGenericCacheThunk

Generic thunk for async function with cache feature

Import

import { createGenericCacheThunk } from '@empeek-rnd-ui/redux/toolkit';

Usage

thunks.ts

const fetchUsers = createGenericCacheThunk(
  'common/fetchUsers',
  () => api.admin.getPotentialAdmins()
);

This thunk works like createGenericThunk, but with cache feature. It is usefully when you use some select and to load data just only once.

It will cache list of users and if you will trigger thunk again it will not start again.

Parameters

This Thunk has not required params

interface ICommonThunkParams {
  force?: boolean;
  reload?: boolean;
}

dispatch(fetchUsers({ force: true }));
dispatch(fetchUsers({ reload: true }));

force - used for update data forced (it doesn't meter if data is loaded ot not)

reload - used for update data if it is already loaded