In our case googleMapsApiKey is provided by our server API. So we need to skip initialization until config data are loaded. That can be kinda tricky, since early return in body of hook or conditional call of other hooks is not recomended in hooks. Also in api of useLoadScript hook is googleMapsApiKey marked as required so we need to ts ignore there
Proposed solution
One way to solve this is make googleMapsApiKey and add check if is nullish here
Other solution is leave it required, but add another attribute skip: boolean, which will early return in useEffect also here. In our case we would provide googleMapsApiKey: "", skip: true. Which is kinda hacky but doesn't require change of api (just addition).
I can provide PR, which solution would you prefer? Is there any other way you can think of?
Please provide an explanation of the issue
In our case
googleMapsApiKey
is provided by our server API. So we need to skip initialization until config data are loaded. That can be kinda tricky, since early return in body of hook or conditional call of other hooks is not recomended in hooks. Also in api ofuseLoadScript
hook isgoogleMapsApiKey
marked as required so we need to ts ignore thereProposed solution
googleMapsApiKey
and add check if is nullish hereskip: boolean
, which will early return in useEffect also here. In our case we would providegoogleMapsApiKey: "", skip: true
. Which is kinda hacky but doesn't require change of api (just addition).I can provide PR, which solution would you prefer? Is there any other way you can think of?