mobx-fetch-tracker
v1.0.0
Published
Easy way to deal with request processing
Downloads
7
Maintainers
Readme
mobx-fetch-tracker
Easy way to deal with request processing
Installation & Usage
NPM: npm install mobx-fetch-tracker --save
import { FetchTracker } from 'mobx-fetch-tracker';
Parameters
fetchUrl
fetcher?
fetchLike functionpreloadData?
initial data if you needrefreshInterval?
interval for auto refreshoptions?
fetch optionsparser?
function to parse responseautoFetch?
if true, fetch will be called after creation of instance
Methods
setOptions
load
off
- stop auto refresh
Example
import { FetchTracker } from 'mobx-fetch-tracker';
import { reaction } from 'mobx';
const parser = 'your parser function'
const { data, isLoading } = new FetchTracker<IParsedData, IRawResponseDara>({
fetchUrl: 'https://jsonplaceholder.typicode.com/todos/1',
parser: parser,
autoFetch: true,
refreshInterval: 60_000,
});
heightData.load();
reaction(
() => data,
(data) => {
console.log(data);
},
);