const allUsers = useFetch(fetchUsersApi, [id]); const usersWithoutAccess = useFetch(fetchUsersApi, [id, queryParams]); const { data: permission } = useFetch(fetchPermissionApi, [id]); const users = permission.value ? allUsers : usersWithoutAccess;
No, you cannot call hooks conditionally1. Every time you render you must call exactly the same hooks in exactly the same order. If you don't, react can't tell which hook corresponds to which, so it can result in things like the wrong state being returned from a useState
hook.
Fixing this typically is done one of two ways:
null
could indicate that it should not fetch.If you'd like details on how to do these, please edit your question to include the code for useFetch