-
Notifications
You must be signed in to change notification settings - Fork 793
[@apollo/react-hooks] can data
be undefined
?
#3192
Comments
This has been a topic of discussion before, but as far as I remember it was decided to not return an empty object by default as this would be a pretty big breaking change and cause quite some issues for existing code, I'm not sure if this behavior is changing now with 3.0. Also keep in mind that when a query errors you will most likely get The docs & types also reflect this:
edit: Also see #2424 |
Thanks for the answer, I notice most often than not, Anyways, this can be easily tweaked by doing:
to say that it's not a big issue, and may actually be a good thing so that people who prefer to get |
I'm not sure, I think the behavior is pretty inconsistent and depends on errors, cache, etc. I'm always checking whether data exists before accessing as we've been bitten by it before and I'd suggest you do the same :) |
Thanks for reporting this @FezVrasta. Yes, this is a bit annoying for sure; we need to align this across the board. |
Okay, here's how things are currently setup in
The above is the current approach we're planning on launching with React Apollo 3. While not perfect, it seems to be the best way to meet in the middle of developer usability and correctness. @FezVrasta the above means that the example you provided earlier in this issue thread would never throw the error, as If anyone objects to this approach definitely let me know. Thanks! |
@hwillson I was just trying out the Apollo hooks package for the first time while migrating away from |
@hwillson It's okay for P.S. Adding an initial value for the data might encompass the best of both worlds |
@mateja176 We're changing things around so |
Intended outcome:
I'm using
@apollo/react-hooks#useQuery
and I noticed sometimesdata
can be set toundefined
. I would expect it to always return an object, even if empty during loading or in case of errors.Actual outcome:
data
can beundefined
, I don't understand if this is expected?How to reproduce the issue:
Version
@apollo/react-hooks@0.1.0-beta.10
The text was updated successfully, but these errors were encountered: