Created
January 27, 2021 11:47
-
-
Save marufsiddiqui/419b10813c33d3fbfae43b5b4deaa583 to your computer and use it in GitHub Desktop.
useE2EMock hook
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { useLocation } from 'react-router' | |
import { parse } from 'qs' | |
import { useEffect, useRef } from 'react' | |
interface Params { | |
refetch: () => void | |
shouldSkip?: boolean | |
} | |
export const useE2EMock = ({ refetch, shouldSkip = false }: Params): void => { | |
const { search } = useLocation() | |
const queryParams = parse(search, { ignoreQueryPrefix: true }) | |
const isMounted = useRef(false) | |
const isE2EMock = queryParams?.e2emock === 'true' | |
useEffect(() => { | |
if (!isMounted.current && isE2EMock && !shouldSkip) { | |
isMounted.current = true | |
console.log('refetch') | |
refetch() | |
} | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment