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

185
Views
How to use react hooks inside of HOC component?

I have a problem making a HOC component with hooks inside.

I am trying to find a correct solution to not break rules-of-hooks.

If I change the name of this component to start with lowercase: withNetworkDetector instead of uppercase, I will not get errors, but did I break the rule then?

Is this code will be secure then?

export const WithNetworkDetector = (Component: FC<{}>) => (props: any) => {
  const [isDisconnected, setIsDisconnected] = useState(false);

  const handleConnectionChange = useCallback(() => {
   ...
    setIsDisconnected(true);
  }, []);

  
  return (
    <div>
      {isDisconnected && (
          <Toast type="warning" text={TOAST_ERRORS.LOST_INTERNET_CONNECTION} />
      )}
      <Component />
    </div>
  );
};

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

0

Hooks can be used inside the React functional component. One of the criterias that classify a function as a react function is the name starting in uppercase, then only we can use that as a React component. So, it will break the rule.

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!