Created
August 22, 2018 07:29
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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