You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I prefer having loading initially set to true because I came from @apollo/react-hooks, which have loading of true when it first renders, so we only need to guard the loading instead of both loading and data.
Also, it doesn't look like you're using TS in this app, but something to be aware of: in your code example, having loading be true initially would not make accessing data.firstName typesafe.
You would either need a runtime check:
<div>{data&&data.firstName}</div>
or a default value for data:
const{ data ={}, loading, error }=useAxios({url: API_URL});
I noticed
loading
inuseAxios
is initially set tofalse
, which causes bug in my program.For example:
It is causing bug because
loading
is initially set tofalse
, so<div>{data.firstName}</div>
is being rendered and gotfirstName
ofundefined
.The text was updated successfully, but these errors were encountered: