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

243
Views
Control html dynamically without component re rendering in React with Apollo

In my current situation, I use Apollo useQuery to fetch a user and their posts.

The posts render in a summary view and in a detailed view. the detailed view is sitting on top of the summary view and its visibility is controlled by a piece of state.

  const { data: userData, error: userError } = useQuery(GET_USER_BY_ID, { // the data fetch
    variables: {
      userId: getUserId(),
    }
  })


  const [showPosts, setShowPosts] = useState(false) // controls toggle between views

the problem im having is every time the showPosts state changes the component re renders and the useQuery is run again. which I do not want. I have already got all my data, I just want to render html without hitting the server again until I need to. What is a potential solution to my problem?

about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Check skip param, You can do something like this:

const { data: userData, error: userError } = useQuery(GET_USER_BY_ID, { // the data fetch
        variables: {
          userId: getUserId(),
          skip:!showPosts
        }
      })

or use useLazyQuery

about 4 years ago · Santiago Trujillo 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!