Skip to content

Latest commit

 

History

History
65 lines (45 loc) · 1.44 KB

File metadata and controls

65 lines (45 loc) · 1.44 KB

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