Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
promer94 committed Nov 17, 2020
1 parent db6b62f commit 9f3428e
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/use-swr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -315,8 +315,9 @@ function useSWR<Data = any, Error = any>(
shouldUpdateState = true
}
}

if (shouldUpdateState || config.suspense) {
if (unmountedRef.current) return
if (unmountedRef.current || !firstMountedRef.current) return
rerender({})
}
}, [])
Expand All @@ -325,6 +326,8 @@ function useSWR<Data = any, Error = any>(
const unmountedRef = useRef(false)
const keyRef = useRef(key)

const firstMountedRef = useRef(false)

// do unmount check for callbacks
const eventsRef = useRef({
emit: (event, ...params) => {
Expand Down Expand Up @@ -536,6 +539,8 @@ function useSWR<Data = any, Error = any>(
// after `key` updates, we need to mark it as mounted
unmountedRef.current = false

firstMountedRef.current = true

// after the component is mounted (hydrated),
// we need to update the data from the cache
// and trigger a revalidation
Expand Down

0 comments on commit 9f3428e

Please sign in to comment.