Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

278
Views
Trying to log a data object in the console using dot notation and it doesn't work, why?

I have a React project using Graphql and Mongo. When doing a query, I'm trying to log the returned data in the console through dot notation and it return "undefined".

I can't fathom Why??

My Component:

import { useQuery } from "@apollo/client";
import React, { useEffect } from "react";
import { GET_USER_SETTINGS } from "../graphql/getUserTimeSetting";

const UserAuthSettings = ({ isAuthenticated, toggle, user = { name: "" } }) => {
  const { data, loading, error } = useQuery(GET_USER_SETTINGS, {
    variables: { userName: user.name },
    options: {
      awaitRefetchQueries: true,
    },
  });

  console.log(data.userTimeSetting);

 
  if (loading) return <div>Submitting...</div>;
  if (error) return <div>{error.message}</div>;

  return null;
};

export default UserAuthSettings;

Console enter image description here

If I only "console.log(data) enter image description here

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Ok I found the answer.

To use or "consume" the data with Apollo/client hooks, you need to do it once you make sure the data exist.

In other words, the code block

if (loading) return <div>Submitting...</div>;
  if (error) return <div>{error.message}</div>;

must come before my console.log(data) - otherwise the query is still in flight and react could not verify the existence of the data. Hence the error.

Fantastic, moving one.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!