Quantcast
Channel: Active questions tagged react-native+typescript - Stack Overflow
Viewing all articles
Browse latest Browse all 6213

Async Await API call inside componentDidMount() is suddenly failing/exceeding timeout? React-Native. Redux. Typescript

$
0
0

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);  };}

Viewing all articles
Browse latest Browse all 6213

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>