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

125
Views
Need explanation of conditional statement using `typeof + React.isValidElement` especially in React Native

I'm confused about this condition

  1. condition using typeof and React.isValidElement
if (
  typeof props.headerComponent == "function" &&
  React.isValidElement(props.headerComponent())
)
  return props.headerComponent();
  1. condition only use typeof
if (typeof props.footerComponent == 'function')
  return props.footerComponent();

if i used 1st condition, there's no error but when i used 2nd condition React show me

Error: RenderFooter(...): Nothing was returned from render. This usually means a return statement is missing. Or, to render nothing, return null.

someone can tell me what's the different between 1st and 2nd condition ?

i thought both of it return a function

const Custom = (props) => {
  const RenderHeader = () => {
    if (
      typeof props.headerComponent == 'function' &&
      React.isValidElement(props.headerComponent())
    )
      return props.headerComponent();
    else if (React.isValidElement(props.headerComponent))
      return props.headerComponent;
    else return null;
  };

  const RenderFooter = () => {
    if (typeof props.footerComponent == 'function')
      return props.footerComponent();
    else if (React.isValidElement(props.footerComponent))
      return props.footerComponent;
    else return null;
  };

  return (
    <div>
      <RenderHeader />
      <RenderFooter />
    </div>
  );
};

class App extends React.Component {
  render() {
    return (
      <div>
        Hello React!
        <Custom
          headerComponent={() => console.log('header')}
          footerComponent={() => console.log('footer')}
        />
      </div>
    );
  }
}

ReactDOM.render(
    <App/>,
    document.getElementById("root")
);
<div id="root"></div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/17.0.2/umd/react.development.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/17.0.2/umd/react-dom.development.js"></script>

about 4 years ago · Juan Pablo Isaza
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!