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

348
Visualizações
Set Icon for a button: Uncaught TypeError: Failed to execute 'appendChild' on 'Node': parameter 1 is not of type 'Node'

I'm trying to set an icon for a button in react, but it's getting me this error. The setIcon of the Button functionality and the button is like this from the source code:

class Button {
  node: HTMLButtonElement
  icon: SVGElement

  constructor() {
    this.node = document.createElement('button');
    this.node.type = 'button';
    this.icon = null;
  }

  setIcon(icon: SVGElement) {
    this.icon = icon;
    this.node.appendChild(icon);
  }

The button is from a librabry that written in TypeScript as mapbox control button.

The icon I am using is from MUI,

import AdjustIcon from '@mui/icons-material/Adjust'

What I did is this.back.setIcon(AdjustIcon); And this.back.setIcon(<AdjustIcon/>); Both are not working and give the same error message:

Uncaught TypeError: Failed to execute 'appendChild' on 'Node': parameter 1 is not of type 'Node'.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

The issue has been fixed, <AdjustIcon/> is a react element but not a DOM node.

However .appendchild() is expecting a DOM node as parameter, and that caused the error.

The solution of this is convert <AdjustIcon/> to a DOM node, and I was using ReactDOM.render() to do that.

    const container = document.createElement('icon');
    ReactDOM.render(<AdjustIcon />, container);
    this.back.setIcon(container);

Using document.createElement() to create a container, and call ReactDOM.render() to render the icon into that container. Then just simply use that container as the icon node.

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