From cbbec269bf440d2b0c39d801ccd1d205830716b7 Mon Sep 17 00:00:00 2001 From: Viki Date: Fri, 14 Jun 2024 16:07:04 +0800 Subject: [PATCH] chore: refine hooks --- src/create-single-loading/index.tsx | 8 ++++---- src/use-reactive/index.ts | 5 ++--- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/create-single-loading/index.tsx b/src/create-single-loading/index.tsx index a6c64cb2..001994a2 100644 --- a/src/create-single-loading/index.tsx +++ b/src/create-single-loading/index.tsx @@ -1,5 +1,5 @@ import { create } from '@shined/reactive' -import { useAsyncFn as _useAsyncFn } from '../use-async-fn' +import { useAsyncFn as useAsyncFnOrigin } from '../use-async-fn' import type { ReactNode } from 'react' import type { UseAsyncFnReturn } from '../use-async-fn' @@ -63,9 +63,9 @@ export function createSingleLoading(options: CreateSingleLoadingOptions = {}): C store.mutate.loading = true try { - const res = await func(...args) + const result = await func(...args) store.mutate.loading = false - return res + return result } catch (error) { if (resetOnError) { store.mutate.loading = initialState @@ -92,7 +92,7 @@ export function createSingleLoading(options: CreateSingleLoadingOptions = {}): C function useAsyncFn(asyncFunc: T) { const loading = useLoading() - const { run, value, error } = _useAsyncFn(bind(asyncFunc)) + const { run, value, error } = useAsyncFnOrigin(bind(asyncFunc)) return { run, diff --git a/src/use-reactive/index.ts b/src/use-reactive/index.ts index ec8b3161..55f25959 100644 --- a/src/use-reactive/index.ts +++ b/src/use-reactive/index.ts @@ -1,5 +1,4 @@ import { create } from '@shined/reactive' -import { useRef } from 'react' import { useCreation } from '../use-creation' // TODO: export from @shined/reactive @@ -14,6 +13,6 @@ export function useReactive( initialState: State, options: SnapshotOptions = {}, ): [State, State] { - const store = useRef(useCreation(() => create(initialState))) - return [store.current.useSnapshot(options), store.current.mutate] as const + const store = useCreation(() => create(initialState)) + return [store.useSnapshot(options), store.mutate] as const }