-1

I tried to add a React.icon too my button, but it's a react component (with this syntax: ). My question now is how can I append this exact icon component to my button Element with DOM Manipulation? This is my current code:

        const para = document.createElement("p");
        const node = document.createTextNode("New Button");
        const uList = document.getElementById("uList");
        const btn = <button ><BsIcons.BsClockHistory /></button>
        listEl.appendChild(btn);
        para.appendChild(node);
        listEl.appendChild(para);
        uList.appendChild(listEl);
  • You don't. Why would you do this? React do `createElement` for you. You shouldn't ever use it by yourself. – Konrad Jul 08 '22 at 18:59
  • Did you develop/create the React.Icon component ? In that case you can append in the `componentDidMount` method. – Nice Books Jul 08 '22 at 18:59
  • Does this answer your question? [How to append React components to HTML element using .append()](https://stackoverflow.com/questions/59899729/how-to-append-react-components-to-html-element-using-append) – AndrewL64 Jul 08 '22 at 18:59
  • @KonradLinkowski Could you elaborate further? I'm kinda new to React and the docs can't help me further sadly – SlothOnCrack Jul 08 '22 at 19:23
  • Please first read how to use it https://beta.reactjs.org/learn – Konrad Jul 08 '22 at 19:28

1 Answers1

0

You can build a Web Component from the React Code and then append it to any HTML element.

  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jul 09 '22 at 06:22