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
React.cloneElement issue (React Top-Level API)

I am playing with React Top-Level API to get a feel how it works and I can't get it to clone a component.

I have a UserButton component that should clone Button component but add a text in the beginning.

Live code: https://codesandbox.io/s/react-cloneelement-issue-4j2ur?file=/src/App.js

export default function App() {
  return (
    <div className="gap-2 flex">
      <Button>Login</Button>

      {/* Expected to get a button that says:
            "Hello! nice to see you Alex"*/}
      <UserButton>Alex</UserButton>
    </div>
  );
}

export function Button({ children, label, className }) {
  return (
    <div
      className={`py-2 px-4 bg-purple-800 hover:bg-purple-900 inline-block rounded text-white cursor-pointer ${className}`}
    >
      {label} {children}
    </div>
  );
}

export function UserButton() {
  // React.cloneElement not working
  return React.cloneElement(Button, {
    label: "Hello! nice to see you"
  });
}

The error I am getting:

Error Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined. You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.

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