Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

186
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda