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

115
Views
HOC inside react hook, causes infinite rerenders

Im attempting to return a HOC component from within the hook.

Let's say I have a top level component as...

function Component(props){
  //do something with props;
  return <h1>Hello {props.title}</h1>
}

And a hook which knows some props, and wants to free the user from providing those props

function useHook(){
  //somehow get prop values at runtime(say title)
  const title = //get from API call;
  return (props) => <Component title={title} {...props}/>
}

Any idea why infinite rerendering happens here? Should I be using useCallback?

about 4 years ago · Santiago Gelvez
1 answers
Answer question

0

React Hooks return children wrapping component

The Problem was addressed here. useCallback solved the infinite re-render. Looks like the hook was recreating the component upon every run (function reference changes upon every run, though it looks like its the same function).

function useHook(){
  //somehow get prop values at runtime(say title)
  const title = //get from API call;
  return useCallback((props) => <Component title={title} {...props}/>,[title]);
}
about 4 years ago · Santiago Gelvez 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!