0👍
You question is quite broad and it really depends on your app and framework, but i’ll try to pinpoint some common use cases:
- Every framework has the interceptors concept (Vue,Angular,React), and it’s good to use them as you suggested
- Regarding the case you mentioned, that the app pings an API and notifies the user many time – you can easily get over it by using a boolean like
showedMessage
, if it’s false you turn it to true and show the message to the user, next time the network is back, you turn it back to false. that way you only show the network down message, once. - Redux is not unique to React and there are implementations for angular (ngrx) and Vue (vuex), they all work on the same concept of handling one major state object that all the components share. This is the recommended method as of now. Another option is mobx, but it’s less common and I think only react has an implementation for it.
- Another way is to use custom events but i would only recommend it for small apps that have no more than 5 event types, otherwise you’ll loose track of what’s happening real soon.
Source:stackexchange.com