facebook / facebook/relay

skip in useFragment

Open
#3,853 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Rust
Stars
19k
Forks
1.9k
PR merge metrics
No merged PRs in 30d

Description

As many others before me I have reached the issue of conditional useLazyLoadQuery or useQuery hooks. I see [Issue 57](https://github.com/relay-tools/relay-hooks/issues/57) [Issue 3370](https://github.com/facebook/relay/issues/3370) discussed this and options {skip:true} was introduced.

However it is not clear what pattern should be then used for useFragment? For example, if I have a query that uses a fragment and then uses options to skip the query then the data subsequently passed to the useFragment will be null and react-relay will complain that it cannot find data. Obviously I can't use hooks conditionally so either 'skip' option needs to flow through all relay hooks or there should be a pattern for this.

```
const query= useLazyLoadQuery(myQuery, {}, {skip:true});
const data = useFragment(myFragment, query); // fails: 'Invariant Violation: Relay: Expected to receive an object where `...myFragment_frag` was spread, but the fragment reference was not found`.
```

How can I solve this without using conditions?

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.