# Optimizing Data Fetching with Apollo Client: Leveraging useFragment and Colocated Fragments

DevFeed: [Optimizing Data Fetching with Apollo Client: Leveraging useFragment and Colocated Fragments](<https://devfeed.tech/articles/optimizing-data-fetching-with-apollo-client-leveraging-usefragment-and-colocated-fragments-23477.md>)

Original publisher: [Read original article](<https://www.apollographql.com/blog/optimizing-data-fetching-with-apollo-client-leveraging-usefragment-and-colocated-fragments>)

Author: Tyler Goelz

Published: 2024-05-10T10:50:08Z

Content type: article

Language: en

Sources: [Apollo Blog](<https://devfeed.tech/sources/apollo-blog.md>)

Topics: [apollo-client](<https://devfeed.tech/topics/apollo-client.md>), [Cache](<https://devfeed.tech/topics/cache.md>)

Tags: [apollo](<https://devfeed.tech/tags/apollo.md>), [apollo-client](<https://devfeed.tech/tags/apollo-client.md>), [cache](<https://devfeed.tech/tags/cache.md>), [components](<https://devfeed.tech/tags/components.md>), [fetching](<https://devfeed.tech/tags/fetching.md>), [fragments](<https://devfeed.tech/tags/fragments.md>), [maintainability](<https://devfeed.tech/tags/maintainability.md>), [performance](<https://devfeed.tech/tags/performance.md>), [react](<https://devfeed.tech/tags/react.md>), [relay](<https://devfeed.tech/tags/relay.md>), [responsibility](<https://devfeed.tech/tags/responsibility.md>)

## AI overview

The excerpt presents Apollo Client's useFragment hook with colocated fragments as a way to keep data needs declared near the components that use them without making those components responsible for fetching. Earlier colocated-fragment approaches still relied on parents passing fragment data through props or components accessing the cache manually; useFragment provides direct access to fragment data in Apollo's normalized cache. The author says this helped their team reduce over-fetching and improve maintainability while preserving the practice of querying only needed data. The hook was introduced in Apollo Client 3.7 and stabilized in 3.8. The supplied text ends mid-sentence, so it does not provide the full implementation or results.

## Source excerpt

When building complex applications today, Apollo Client users typically reach for to get data to their components. This is no surprise as this is considered a best practice by the Apollo Client documentation. However, this can cause challenges while trying to minimize over-fetching while maintaining a clear separation of concern.