Skip to content

Commit

Permalink
🚑 Improve initial state in useAsyncState and remove additional effe…
Browse files Browse the repository at this point in the history
…ct in `useRUD`
  • Loading branch information
exah committed Mar 16, 2020
1 parent 5edfc3f commit 5509bd8
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export type Store<D extends Data = Data> = {

export type AsyncState<T> =
// initial
| { isReady: null; isLoading: false; error: null; result: null }
| { isReady: false; isLoading: false; error: null; result: null }
// ready
| { isReady: true; isLoading: false; error: null; result: T }
// loading
Expand Down
2 changes: 1 addition & 1 deletion src/use-async-state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { useReducer, useMemo } from 'react'
import { AsyncState } from './types'

export const INITIAL_STATE: AsyncState<null> = {
isReady: null,
isReady: false,
isLoading: false,
error: null,
result: null,
Expand Down
5 changes: 0 additions & 5 deletions src/use-rud.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,6 @@ function useClientData<T>(fetcher: Fetcher<T>, key: Key): AsyncState<T> {
useLayoutEffect(() => {
if (store.exists(key)) {
store.remove(key)
}
}, [store, key])

useLayoutEffect(() => {
if (store.exists(key)) {
return
}

Expand Down

0 comments on commit 5509bd8

Please sign in to comment.