I call multiple graphql query using useQuery. And it's shows error like
Too many re-renders. React limits the number of renders to prevent an infinite loop.
I know why it came but i don't know how to prevent from this error. This is Functional components
my code here
const [categoryList, updateCategoryList] = useState([]);
const [payeeList, updatePayeeList] = useState([]);
if (data) {
const categories = (data.categories as unknown) as Category[];
if (
!isEqual(categoryList, categories) ||
categoryList.length !== categories.length
) {
updateCategoryList([...categories]);
}
}
if (isEmpty(payeeList)) {
const { loading, data } = useQuery(payeesQuery);
if (data) {
const payees = (data.payees as unknown) as Payee[];
if (!isEqual(payeeList, payees) || payeeList.length !== payees.length) {
updateCategoryList([...payees]);
}
}
}
Sorry guys I noob for react.
ifcondition