React Caveats
#
All scalars can be undefined?For gqless
to be able to work, in the first pass of your data usage, every GraphQL Scalar and Enum is returned as undefined
,
after that, the data requirement is acknowledged by gqless
, and when the data arrives from the GraphQL API, it returns the new value instead.
We will often call them Skeleton value
.
One important thing to note is that the "Skeleton value" is different than null
(which was used in the early designs),
which allows you differentiate between when it's a "Skeleton value" or an actual null
coming from the API, and it also allows you to easily set default values to replace only the "Skeleton value" while destructuring.
#
Using lists in ReactThe fact that we use undefined
as "Skeleton value" implies a little inconvenience while rendering lists in React
.
When using a GraphQL scalar as key
, React
doesn't accept undefined
as a key value, and warns about it in the first render of your components
To fix this issue, you have two alternatives:
- If you are destructuring, you can use
=
in your target key:
- Or if you are passing the whole object to be used by another component, you can do:
In both cases we recommend defaulting to a
key
you can be sure won't appear in your data, or if you are not sure about it, you can use the second method, and default to a different type of value.