Hi!
The easiest option would be storing the error in Redux and showing the alert in componentDidUpdate when you detect that it has changed:
componentDidUpdate (prevProps) {
if (!prevProps.error && this.props.error) {
// show the alert
}
}
Another option is invoking directly the alert directly from redux-thunk (I'm assuming you're using it for handling the fetching).
An even cleaner solution though (in my opinion) is achieved using something like redux-saga for triggering the side effect (the alert) when an error action is dispatched.
P.S.: Let me know if you need any example of the suggestions above :)
Matteo Mazzarolo
Engineer @invisionapp