You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Would love to have some input from Relay's team about the best practices here.
TLDR is that we want to standardize how we fetch data and we are debating between 2 patterns:
Loading data inside of hooks
exportconstuseCopyProfileUrl=({
userProfileRef,
utmTag,}: {userProfileRef: useCopyProfileUrl_userProfile$key;utmTag?: {utm_campaign: string;utm_medium: string;utm_source: string;};})=>{constuserProfile=useFragment<useCopyProfileUrl_userProfile$key>(graphql` fragment useCopyProfileUrl_userProfile on UserProfile { displayUsername } `,userProfileRef,);// [..]
Pro: data fetching is co-localized with consumption. In theory, if Relay ESLint plugin worked, this would provide us protection against data over-fetching.
Con: need to add useCopyProfileUrl_userProfile fragment to every parent data loader/fragment
Con: additional suspense may cause unexpected issues with state management [components losing internal state]
Con: a bit harder to test
Loading data outside of hooks
constprofile=useFragment<ShareProfileMenuButton_userProfile$key>(graphql` fragment ShareProfileMenuButton_userProfile on UserProfile { displayUsername } `,userProfileRef,);const{ onCopyProfileLink }=useCopyProfileUrl({userProfile: {displayUsername: profile.displayUsername,},utmTag: {utm_campaign: 'social_sharing',utm_medium: 'independent_share',utm_source: 'copy_link',},});
Pro: encapsulation
Pro: portability
Pro: ease of testing
Con: the need to explicitly map every property (if we want to retain static analyzes for over-fetching protection)
Con: easy to over-fetch since the former cannot be enforced
What's the recommended path and what are your arguments for it?
The text was updated successfully, but these errors were encountered:
Related Loom discussing an internal PR: https://www.loom.com/share/670823d870084f7b920d368802463761
Would love to have some input from Relay's team about the best practices here.
TLDR is that we want to standardize how we fetch data and we are debating between 2 patterns:
Loading data inside of hooks
useCopyProfileUrl_userProfile
fragment to every parent data loader/fragmentLoading data outside of hooks
What's the recommended path and what are your arguments for it?
The text was updated successfully, but these errors were encountered: