Skip to content

Instantly share code, notes, and snippets.

@marufsiddiqui
Created January 27, 2021 11:47
Show Gist options
  • Save marufsiddiqui/419b10813c33d3fbfae43b5b4deaa583 to your computer and use it in GitHub Desktop.
Save marufsiddiqui/419b10813c33d3fbfae43b5b4deaa583 to your computer and use it in GitHub Desktop.
useE2EMock hook
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