This is what I imagine a type safe way of connecting a React component to a REST endpoint might look like. Heavily opinionated and not production ready, this is an experimental project.
Usage
; ; // All 3 types need to be specified until// https://github.com/Microsoft/TypeScript/issues/10571 is implemented.; ReactDOM.render;
Assumptions
As mentioned, this lib has opinions about how a REST endpoint looks like and how the data it returns looks like.
- All entities can be uniquely identifiable by an
id
key.
Connecting multiple views to the same API
; ; ;; // We'll have a single container querying the API and multiple// views listening to it.;; ReactDOM.render;
Testing
You can create stores with mocked data for use in tests:
; ; mock.state.loading === falsemock.state.response === 1