Skip to content

Commit

Permalink
chore: refine hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
vikiboss committed Jun 14, 2024
1 parent 84ae5c4 commit cbbec26
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
8 changes: 4 additions & 4 deletions src/create-single-loading/index.tsx
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -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
Expand All @@ -92,7 +92,7 @@ export function createSingleLoading(options: CreateSingleLoadingOptions = {}): C

function useAsyncFn<T extends AnyFunc>(asyncFunc: T) {
const loading = useLoading()
const { run, value, error } = _useAsyncFn(bind(asyncFunc))
const { run, value, error } = useAsyncFnOrigin(bind(asyncFunc))

return {
run,
Expand Down
5 changes: 2 additions & 3 deletions src/use-reactive/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { create } from '@shined/reactive'
import { useRef } from 'react'
import { useCreation } from '../use-creation'

// TODO: export from @shined/reactive
Expand All @@ -14,6 +13,6 @@ export function useReactive<State extends object>(
initialState: State,
options: SnapshotOptions<State> = {},
): [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
}

0 comments on commit cbbec26

Please sign in to comment.