A query HOC for doing a request when the passed component is mounted.
...
// refresh request:
this.props.myRequest.refreshRequest()
...
import { query } from 'retrievejs';
const enhance = query(api.getMockData, 'myRequest')
export const MyComponent = enhance((props) => <pre>{JSON.stringify(props, null, 4)}</pre>)
const MyComponent = (props) => {
// props.myRequest.request
// => axios request object
// props.myRequest.isFetching
// => whether or not we're currently fetching a resource
// props.myRequest.failed
// => if the request failed, if yes, equals to true
}
Generated using TypeDoc
Creates an api object which contains functions depending on the endpoint object passed in the 1st parameter.
Example (es imports)
import { createApi } from 'retrievejs'; const endpoints = { getMock: { path: 'http://www.mocky.io/v2/5aab93182e00004900138dd4', method: 'get' } }; const api = createApi(endpoints); // => api.getMock().then((response) => console.log(response))