title: React GraphQL - How to return the results of a Query component as an object to use in React context
body: <p>I have a Query component which gets the information of the a user who has logged in. The query itself works but I am having trouble returning the results of the query as an object which I then want to pass to React.createContext()</p>
  
  <p>I am using Apollo client to make my Query component in my React application.</p>
  
  <p>The following is an example of my current code:</p>
  
  <pre><code> function getUser() {
        return (
          &lt;Query query={query.USER_INFO}&gt;
            {({ loading, error, data }) =&gt; {
              if (loading) return &lt;div&gt;Loading&lt;/div&gt;;
              if (error) return &lt;div&gt;error&lt;/div&gt;;
  
              const userInfo = {
                name: data.user.name,
                age: data.user.age,
              }
  
            }}
          &lt;/Query&gt;
        );
      }
  
      //need userInfo object to go here
      export const UserContext = React.createContext(userInfo);
  </code></pre>
  
  <p>How can I get the return of the Query to then use in React.createContext? The reason I want to do it this way is to avoid rewriting this Query in every component where I want info of the user who has logged in.</p>