Here’s my sample code:
const { getConversionList, conversionList } = useConversion();
useEffect(() => {
getConversionList();
}, []);
useConversion is a GraphQL resolver hook, I’m getting Linting error to add dependency. But if I add dependency then it is an infinite rendering.
How can I safely bypass it?
Tried adding dependency by caused infinite rendering. I want useEffect to run only once on load hence added [] as dependency
3
Answers
You may try add this below line.
// eslint-disable-next-line
For your code snippet.
You can ensure that
useEffect
runs only once by using auseRef
hook to track if the effect has already run: