Last active
March 17, 2017 13:55
-
-
Save couzic/eabb695e2e0468e30dceedfbad6d7d7e to your computer and use it in GitHub Desktop.
react-rx-pure-connect General Example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import {connect} from 'react-rx-pure-connect' | |
| interface InternalProps { | |
| name: string | |
| } | |
| const InternalComponent = (props: InternalProps) => <h2>Name: {props.name}</h2> | |
| interface ExternalProps { | |
| personId: number | |
| } | |
| const mapProps = (props: ExternalProps): Observable<InternalProps> => Observable.ajax | |
| .getJSON(`/api/person/${props.personId}`) | |
| .map(person => ({name: person.name})) | |
| const ExternalComponent: React.StatelessComponent<ExternalProps> = connect(mapProps)(InternalComponent) | |
| // Rendered as "<h2>Name: Bob</h2>" | |
| <ExternalComponent personId={123} /> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment