facebook / facebook/relay

[RFC] useLazyFragment hook

Open
#3,486 12 comments 6 reactions 0 assignees View on GitHub
Dominant language
Rust
Stars
19k
Forks
1.9k
PR merge metrics
No merged PRs in 30d

Description

I'd like to be able to fetch parts of a query only when the component calling a new "useLazyFragment" hook is rendered.

Think of a page that has many tabs with a lot of data to be rendered inside these tabs. It would be wasteful to fetch all data from all tabs when the user might not click any of them. Using this hook, when the user clicks a tab the component would suspend and a query generated by the compiler (similar to useRefetchableQuery) would be fired to get the data that tab needs.

Another good case for this is a list of items and when you click an item it expands to show more details. You could write another query for the item's details but with this hook Relay would generate the query for you.

The current solution is to fire separate queries in each tab, which imo isn't a satisfying approach in many cases. This hook would let the user take even more advantage of graphql's schema composability, and the server would need to write less queries.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.