-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathexample.js
24 lines (21 loc) · 841 Bytes
/
example.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import React from 'react'
import axios from 'axios'
import useFetchData from './index'
/**
* @param {*} url url
* @param {*} initState setInit state, defaultValue: undefined
* @return {array} [state, memoizedFetchDateApi] state: { data, isLoading, error, ... }
*/
export const useFetchDataGet = (url, initState) => {
const [state, memoizedFetchDateApi] = useFetchData(data => axios.get(url, { params: data }), initState)
return [state, memoizedFetchDateApi]
}
/**
* @param {*} url url
* @param {*} initState setInit state, defaultValue: undefined
* @return {array} [state, memoizedFetchDateApi] state: { data, isLoading, error, ... }
*/
export const useFetchDataPost = (url, initState) => {
const [state, memoizedFetchDateApi] = useFetchData(data => axios.post(url, data), initState)
return [state, memoizedFetchDateApi]
}