I’m using RTK Query and It was required in the appplication to call certain query conditionally, so I did it by using if/else conditions and called the query hooks inside if/else blocks instead of using skip prop, and amzaingly it worked absolutely fine, react didn’t throw any error, not even warning. Why? We know that React strictly tells to use hooks at top in the component and not call them conditionally.
let organizations;
if (role !== 'teamAdmin' && role !== 'orgAdmin') {
const { data: response } = useGetOrganizationsQuery({});
organizations = response;
}
so my question is how can this work?
New contributor
Muhammad Hamza is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.