react-data-fetch

0.5.0 • Public • Published

react-data-fetch Build Status Coverage Status

A good-enough data fetching mixin for React components. No models, no stores, just data.

Bare functionality for fetching server-side JSON data inside a React omponent. Uses basic Ajax requests and setInterval for polling.

{
  "component": "List",
  "dataUrl": "/api/users.json",
  // Refresh users every 5 seconds
  "pollInterval": 5000
}

Props:

  • dataUrl - A URL to fetch data from. Once data is received it will be set inside the component's state, under the data key, and will cause a reactive re-render.
  • pollInterval - An interval in milliseconds for polling the data URL. Defaults to 0, which means no polling.

Context methods:

  • getDataUrl: The data URL can be generated dynamically by composing it using other props, inside a custom method that receives the next props as arguments and returns the data URL. The expected method name is "getDataUrl" and overrides the dataUrl prop when implemented.

The DataFetch mixin introduces a jQuery dependency, its built-in JSONP support is worth the money.

Readme

Keywords

none

Package Sidebar

Install

npm i react-data-fetch

Weekly Downloads

10

Version

0.5.0

License

none

Last publish

Collaborators

  • nighttrax
  • skidding
  • valentin-radulescu-hs