I have value X
coming from the server. I would like to expose an interface similar to
interface Xclient {
getX(): Promise<X>
}
that I will later use from my react function component.
I say similar because behind the scenes I want it to:
- first return value from the storage (its react-native)
- simultaneously dispatch network call for newer version of X and re-render the component once I have the response
so instead of Promise
I probably need Observable
. But then how to use it with react in general and react hooks in particular?
I'm coming from the backend background so there may be some more canonical approach that I dont know about. I really dont want to use redux
if possible!