From 87b498db01872ad97e3f01ed715dc3d5552e464d Mon Sep 17 00:00:00 2001 From: Jonathan Verrecchia Date: Sun, 29 Sep 2019 15:45:21 +0900 Subject: [PATCH] Add useCache option for standard useAxios call --- index.d.ts | 1 + src/index.js | 9 +++++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/index.d.ts b/index.d.ts index e3b44892..12bbe272 100644 --- a/index.d.ts +++ b/index.d.ts @@ -17,6 +17,7 @@ interface ResponseValues { interface Options { manual?: boolean; + useCache?: boolean; } interface RefetchOptions { diff --git a/src/index.js b/src/index.js index b99873da..f4aea903 100644 --- a/src/index.js +++ b/src/index.js @@ -106,7 +106,10 @@ function executeRequestWithoutCache(config, dispatch) { return request(config, dispatch) } -export default function useAxios(config, options = { manual: false }) { +export default function useAxios( + config, + options = { manual: false, useCache: true } +) { if (typeof config === 'string') { config = { url: config @@ -124,7 +127,9 @@ export default function useAxios(config, options = { manual: false }) { React.useEffect(() => { if (!options.manual) { - executeRequestWithCache(config, dispatch) + options.useCache + ? executeRequestWithCache(config, dispatch) + : executeRequestWithoutCache(config, dispatch) } }, [JSON.stringify(config)])