Problem: In React Query, a mutation often needs access to the query's key so...


Problem: In React Query, a mutation often needs access to the query's key so it can clear cache.

Solution: Put associated queries and mutations in the same custom hook.

This colocates related code, and makes sharing query keys easy.

Oops, my solution had a typo.

Solution: Put associated query and mutation custom hooks *in the same file*.

View original on X