react-wildcat-prefetch
v9.0.0
Published
A React decorator to prefetch component data.
Downloads
21
Keywords
Readme
react-wildcat-prefetch
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);
}
}