npm

Need private packages and team management tools?Check out npm Orgs. »

react-wildcat-prefetch

9.0.0 • Public • Published

react-wildcat-prefetch

npm package

A React higher order component to prefetch component data.

Installation

npm:

npm install react-wildcat-prefetch

Usage

@prefetch({string}|{function} action, [{Object} options])

// Prefetch data from a fully qualified URL
@prefetch("https://example.com/data.json")
 
// Or pass in a function
function getData() {
    return Promise.resolve(/* some data */);
}
@prefetch(getData)
 
// By default the key name is `asyncData`, but you
// can set your own key name in the options object
@prefetch("https://example.com/data.json", {key: "newKeyName"})

Prefetching Data

Full example can be found in the examples folder

import prefetch from "react-wildcat-prefetch";
 
@prefetch("https://example.com/data.json", {key: "asyncData"})
class PrefetchExample extends React.Component {
    static propTypes = {
        asyncData: PropTypes.object.isRequired
    };
 
    static defaultProps = {
        asyncData: {
            data: []
        }
    };
 
    render() {
        const {asyncData: {data}} = this.props;
        console.log(data);
    }
}
 

License

MIT

Keywords

none

install

npm i react-wildcat-prefetch

Downloadsweekly downloads

49

version

9.0.0

license

MIT

last publish

collaborators

  • avatar
  • avatar
  • avatar
  • avatar
  • avatar
Report a vulnerability