Async call inside componentDidMount is exceeding timeout and failing.
The api call itself is not using redux, but the data retrieved is.
Is this an instance where I would need to use Redux Thunk?How would Thunk be applied to the initial get call?
Can't seem to get passed the initial await call.
Component.tsx
async componentDidMount() { const { resetItems, loadItems } = this.props; try { const stuff: Stuff[] | null = await stuffService.getItems(); if (stuff && stuff.length > 0) { loadItems(stuff); } else { resetItems(); } } catch {} }
stuffService.tsx
function getItems(): Promise<Stuff[] | null> { return request({ url: "Items", method: "GET", });}
index.ts
export function loadItems(stuff: Stuff[]): ActionTypes { return { type: "LOAD_ITEMS", stuff, };}export function resetThings(): ActionTypes { return { type: "RESET_ITEMS", };}
Things I've tried:Moving the call outside of componentDidMount.Using other life cycle methods.Using Thunk on the loadItems();
export function loadItemsAsync(stuff: Stuff[]) { return (dispatch) => { setTimeout(() => { dispatch(loadItems(stuff)); }, 9000); };}