Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

189
Visualizações
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
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda