Skip to content
Discussion options

You must be logged in to vote

Why do we need to have that option?

Because it's not possible to call hooks conditionally. It's also not always easily possible or desired to split things up into multiple components, especially when writing custom hooks. Consider:

const useSomething = () => {
  const userId = useSelector(state => state.user?.id)
  return useQuery({
    queryKey: ['something', userId],
    queryFn: () => fetchSomething(userId),
    enabled: !!userId
  })
}

sure you can split that up into multiple components, but that would mean prop-drilling something that you read from a global client state manager (like redux in this example) and you can't really use custom hooks composition nicely.

it also occurs fr…

Replies: 2 comments 9 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
9 replies
@TkDodo
Comment options

@artem-malko
Comment options

@artem-malko
Comment options

@TkDodo
Comment options

@artem-malko
Comment options

Answer selected by artem-malko
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Ideas
Labels
None yet
2 participants