1
const {authState,loading:authLoading}=useAuthState();
const {
        data,
        loading,
        error
    } = useSubscription(USER_NOTIFICATIONS, { variables: { userId:authState.userId} });

In the above code, I am getting

Cannot read property 'userId' of null because the authState is null when the component loads.

Is there any way to call the useSubscription hook only after the authState is loaded and it is not empty.

I read useSubscription apollo document, there is an attribute named skip which accepts a boolean value.

Is skip will solve this issue? In that case, Is there any code example available?

I cant use like this, because this is against react hooks

    useEffect(() => {
        async function fetchData(){
         if(await authState){
           const {
             data,
             loading,
             error
           } = useSubscription(USER_NOTIFICATIONS, { variables: { userId:authState.userId}});
         }
        }
        if(!authLoading) fetchData();
     }, [authState,authLoading])

0 Answers0