|
|
|
|
|
by hombre_fatal
562 days ago
|
|
How do you write a singleton service that can feed state back into the component that calls it when that state changes? For example, `api.fetchInfo()` would want to feed Loading | Success(T) | Error(E) back into the React component call-site when they change. EventEmitters come to mind but aren't without their own issues like subscription leaks. And you have to track component arguments in order to know when to call the service again when they change which is a classic source of complexity. Hooks provide a solution for this since they themselves are just nested React lifecycle constructs (like useState + useEffect). |
|