From 74fcb2fcfb79e6ea805eb7ca1f0bdb503475a0ea Mon Sep 17 00:00:00 2001 From: ssi02014 Date: Sun, 21 Apr 2024 05:14:53 +0900 Subject: [PATCH] fix: useAsyncProcessQueue --- .github/workflows/document.yml | 2 +- .../src/hooks/useAsyncProcessQueue/index.ts | 22 +++++++++---------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/.github/workflows/document.yml b/.github/workflows/document.yml index 7c2e653f5..4d9c7085c 100644 --- a/.github/workflows/document.yml +++ b/.github/workflows/document.yml @@ -9,7 +9,7 @@ on: jobs: document-publish: runs-on: ubuntu-latest - if: github.event.pull_request.merged == true && github.event.pull_request.user == 'github-actions[bot]' + if: github.event.pull_request.merged == true && github.event.pull_request.user.login == 'github-actions[bot]' steps: - name: Checkout 🔔 uses: actions/checkout@v4 diff --git a/packages/react/src/hooks/useAsyncProcessQueue/index.ts b/packages/react/src/hooks/useAsyncProcessQueue/index.ts index be9af41a8..6aa60cf39 100644 --- a/packages/react/src/hooks/useAsyncProcessQueue/index.ts +++ b/packages/react/src/hooks/useAsyncProcessQueue/index.ts @@ -1,18 +1,18 @@ import { useCallback, useState, useRef } from 'react'; -type RequestFunction = (requestData?: any) => Promise; +type RequestFunction = (requestData?: any) => Promise; interface UseAsyncProcessQueueOptions { keepPreviousData?: boolean; } -export const useAsyncProcessQueue = ({ +export const useAsyncProcessQueue = ({ keepPreviousData = false, }: UseAsyncProcessQueueOptions = {}) => { - const requestQueue = useRef[]>([]); + const requestQueue = useRef[]>([]); - const [data, setData] = useState(); - const [error, setError] = useState(); + const [data, setData] = useState(null); + const [error, setError] = useState(null); const [isLoading, setIsLoading] = useState(false); const handleRequestQueue = useCallback(async () => { @@ -27,10 +27,10 @@ export const useAsyncProcessQueue = ({ const res = await requestFunc(); setData(res); - setError(undefined); + setError(null); } catch (err) { - setData(undefined); - setError(err as Error); + setData(null); + setError(err as E); } finally { requestQueue.current.shift(); setIsLoading(false); @@ -40,13 +40,13 @@ export const useAsyncProcessQueue = ({ }, []); const addToProcessQueue = useCallback( - async (callbackFunc: RequestFunction) => { + async (callbackFunc: RequestFunction) => { requestQueue.current.push(callbackFunc); if (requestQueue.current.length === 1) { if (!keepPreviousData) { - setData(undefined); - setError(undefined); + setData(null); + setError(null); } await handleRequestQueue();