Skip to main content

Posts

Showing posts with the label React Async

React Async

React Async provides a way for React components to subscribe for observable values. Installation React Async is packaged on npm: $ npm install react-async Basic usage React Async provides a component decorator @Async which given a set of observable specifications wraps a regular React component and returns a new one which subscribes to observables and re-renders the component when new data arrives. The basic example looks like: import React from 'react'; import Async from 'react-async'; import Rx from 'rx'; function defineXHRObservable(url) { return { id: url, start() { return Rx.fromPromise(fetch(url)) } } } function MyComponentObservables(props) { return { user: defineXHRObservable(`/api/user?user${props.userID}`) } } @Async(MyComponentObservables) class MyComponent extends React.Component { render() { let {user} = this.props ... } } The @Async decorator in