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

152
Views
How do I disable a component through a condition?

I have a condition (isOnFullDomain()) that returns true, if I am in this condition, the Component can't load.

This is the code i am using:

import Component from 'components/Component';

useEffect(() => {
    Component();
    if (isOnFullDomain()) {
      console.log('remove Component');
    }
  }, [path]);

I really need to remove the component once it's loaded, if I load it once, it's showing up on the screen.

I need something similar to:

if (isOnFullDomain()) {
  Component().remove;
}

Any idea how I can fix it?

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

0

You should be able to achieve that by using JSX, rather than react hooks - usually hooks are move towards data management, react to some value updates and do something about it.

In this case I imagine you have a render method that uses your Component. Hence something like this would make the Component not appear in the page.

import Component from 'components/Component';
// ...
const shouldRenderComponent = !isOnFullDomain();

return (
  {shouldRenderComponent && <Component />
);

Sidenote: if you don't want to load the Component code internally, then you might want to have a look at the import statement and bundle splitting in order to "lazy load" that component.

about 4 years ago · Juan Pablo Isaza Report

0

In the component where you are rendering this component, you could conditionally render it, by doing something like this.

return(...
{!isOnFullDomain() && <ComponentToBeRendered/>}
...
)
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!