urql
urql copied to clipboard
docs: refactored examples that use the logical `!`
Summary
Using the bang operator (!) on non-boolean values can lead to unexpected results. For example, in the case of this example, using the pause
option inside the useQuery
hook, one might set the value of the from
variable to be 0
. In that case the checks would be inaccurate since !0 === true
. However, we only expect to pause the query only when from
or limit
is nullish. We can replace that condition with a more robust one.
Yes, it's an edge case, but new developers reading this documentation might not be aware of the presence of this bug and might have some unexpected results using this example in their code.
Set of changes
Replaced !from || !limit
with the more accurate from === undefined || from === null || limit === undefined || limit === null
in the useQuery
hook/composable on React/Preact Basics and Vue basics.
An intermediate variable shouldPause
got used to avoid inlining that long condition into the pause
option.
⚠️ No Changeset found
Latest commit: 8b2f0caaa3b3186c55ccd6d0bd347598286034ee
Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.
This PR includes no changesets
When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types
Click here to learn what changesets are, and how to add one.
Click here if you're a maintainer who wants to add a changeset to this PR