import axios from 'axios'; import { Dispatch } from 'redux'; import { ActionTypes } from './actionTypes'; import { Category, ApiResponse } from '../../interfaces'; export interface GetCategoriesAction { type: ActionTypes.getCategories | ActionTypes.getCategoriesSuccess | ActionTypes.getCategoriesError; payload: T; } export const getCategories = () => async (dispatch: Dispatch) => { dispatch>({ type: ActionTypes.getCategories, payload: undefined }) try { const res = await axios.get>('/api/categories'); dispatch>({ type: ActionTypes.getCategoriesSuccess, payload: res.data.data }) } catch (err) { console.log(err); } }