From e097315d4c4e80d41900ae2fe4a63c3a30e225b6 Mon Sep 17 00:00:00 2001 From: leozyang Date: Fri, 17 Jul 2020 15:09:56 +0800 Subject: [PATCH] =?UTF-8?q?feat(useFetchData):=20=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E9=94=99=E8=AF=AF=E6=8A=9B=E5=87=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/useFetchData.tsx | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/useFetchData.tsx b/src/useFetchData.tsx index 0066bff5..89df55fd 100644 --- a/src/useFetchData.tsx +++ b/src/useFetchData.tsx @@ -42,12 +42,8 @@ const useFetchData = >( }, ): UseFetchDataAction => { let isMount = true; - const { - defaultPageSize = 20, - defaultCurrent = 1, - onLoad = () => null, - onRequestError = () => null, - } = options || {}; + const { defaultPageSize = 20, defaultCurrent = 1, onLoad = () => null, onRequestError } = + options || {}; const [list, setList] = useState(defaultData as any); const [loading, setLoading] = useState(undefined); @@ -95,7 +91,12 @@ const useFetchData = >( onLoad(data); } } catch (e) { - onRequestError(e); + // 如果没有传递这个方法的话,需要把错误抛出去,以免吞掉错误 + if (onRequestError === undefined) { + throw new Error(e); + } else { + onRequestError(e); + } } finally { setLoading(false); }