React-query tip: You probably don’t need initialData or presetData


React-query tip: You probably don’t need initialData or presetData. If you set these, isLoading is always false.

Solution: Return early. Display a loading spinner when data isn't defined. This assures data is defined. 👍

Then you can safely reference data below the Spinner.

With this approach, I don't need to check "isLoading".

Checking that data is defined is often preferable to using isLoading. Why? Because checking if data is defined narrows the type. isLoading doesn't.

So I just check if data is defined to determine if loading is complete.

View original on X