0

is there a good approach for using useSession (next-auth/react) and useQuery (@apollo/client) together? problem with the code below is that session could possibly undefined here which could cause a 400 error in Graphql, I would only want the query to happen if session is defined

const myComponent = () => {
      const { data: session } = useSession();

      const { loading: user, data: userData } = useQuery<data, dataVar>(
        GET_USER_INFO,
        {
          variables: { userID: session?.user.id as string },
        }
      );
}

juliomalves
  • 42,130
  • 20
  • 150
  • 146
user3226932
  • 2,042
  • 6
  • 39
  • 76
  • Use the `skip` option on the `useQuery` call to conditionally call it. See [use query hook react Apollo conditional call](https://stackoverflow.com/questions/59489097/use-query-hook-react-apollo-conditional-call). – juliomalves Oct 19 '22 at 20:41

0 Answers0