MCPcopy
hub / github.com/simoneb/axios-hooks / makeUseAxios

Function makeUseAxios

src/index.js:61–282  ·  view source on GitHub ↗
(configureOptions)

Source from the content-addressed store, hash-verified

59}
60
61export function makeUseAxios(configureOptions) {
62 /**
63 * @type {import('lru-cache')}
64 */
65 let cache
66 let axiosInstance
67 let defaultOptions
68
69 const __ssrPromises = []
70
71 function resetConfigure() {
72 cache = new LRUCache({ max: 500 })
73 axiosInstance = StaticAxios
74 defaultOptions = DEFAULT_OPTIONS
75 }
76
77 function configure(options = {}) {
78 if (options.axios !== undefined) {
79 axiosInstance = options.axios
80 }
81
82 if (options.cache !== undefined) {
83 cache = options.cache
84 }
85
86 if (options.defaultOptions !== undefined) {
87 defaultOptions = { ...DEFAULT_OPTIONS, ...options.defaultOptions }
88 }
89 }
90
91 resetConfigure()
92 configure(configureOptions)
93
94 function loadCache(data) {
95 cache.load(data)
96 }
97
98 async function serializeCache() {
99 const ssrPromisesCopy = [...__ssrPromises]
100
101 __ssrPromises.length = 0
102
103 await Promise.all(ssrPromisesCopy)
104
105 return cache.dump()
106 }
107
108 function clearCache() {
109 cache.clear()
110 }
111
112 return Object.assign(useAxios, {
113 __ssrPromises,
114 resetConfigure,
115 configure,
116 loadCache,
117 serializeCache,
118 clearCache

Callers 3

index.test.ssr.jsxFile · 0.90
index.test.jsxFile · 0.90
index.jsFile · 0.85

Calls 2

resetConfigureFunction · 0.85
configureFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…