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

181
Views
Pass props into Higher order layout function in Next JS

I have this layout component as Higher Order Component:

import PropTypes from 'prop-types';

Layout.propTypes = {
  children: PropTypes.node.isRequired,
  type: PropTypes.string.isRequired
};

function Layout({ children, type }) {

  return (
    <div>
      {children}
      {type}
    </div>
  );
}

export function withLayout(Component) {
  Component.Layout = Layout;
  return Component;
}

I am using it with another component like this:

import Layout from './

function ChildElement() {

  return (
    <>
      This is the child element
    </>
  );
}

export default withLayout(ChildElement);

How can I pass the type prop into from withLayout(ChildElement)?

I have tried to pass in the type prop into it by passing a prop to <ChildElement type="Hello" /> but that will only work in <ChildElement /> and not withLayout() How do I make it work?

Thanks in advance.

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!