Skip to content

Instantly share code, notes, and snippets.

@HerbertLim
Created August 22, 2018 07:29
Show Gist options
  • Save HerbertLim/c70276317f7be06f9cc886be8b8200e5 to your computer and use it in GitHub Desktop.
Save HerbertLim/c70276317f7be06f9cc886be8b8200e5 to your computer and use it in GitHub Desktop.
Common axios.get with timeout in React Native's action creator. This works well at iOS.
export function myActionCreator() {
return async dispatch => {
try {
req = await axios.get(url, {timeout: 4000});
dispatch ({
type: ACTION_TYPE,
payload: req.data,
})
} catch (e) {
dispatch ({
type: NETWORK_ERROR,
notice: notice_network_error,
})
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment