Remote Data as Data
Today I want to talk about an interesting (though not new) idea for representing remote resources. In fact, any resource that takes some time to retrieve. But most often we talk about network resources. At the same time, we’re going to do a bit of TypeScript gymnastics. Data type for side effects The state of a remote resource can be represented in four ways: Idle - we haven’t even requested the resource yet Loading - we have requested the resource, but the operation is not yet complete Ready<D> - we have the data Error<E> - something has gone wrong So, using a discriminated union feature of TypeScript, we can create a type for this situation:...