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

347
Views
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 answers
Answer question

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 Report
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!