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

    7

    Version

    9.0.0

    License

    MIT

    Unpacked Size

    15.2 kB

    Total Files

    6

    Last publish

    Collaborators

    • carakuei
    • cwelch5
    • djwiebe
    • miblanchard-nfl
    • mikenfl