Skip to content
Advertisement

Adding multiple elements issue using ReactDOM.render in react js

I am new to react js and i am trying to add HTML elements multiple times using ReactDOM.render but when I add elements to the dom multiple times the element is replaced each time not added one by one as a new element

this is my code:

  const questionPreview = document.getElementById('question-preview');

  let input = React.createElement("input",{className:"questionTextInput",name:"textInputQuestion[]"},null);
  ReactDOM.render(input,questionPreview);

Advertisement

Answer

you can use ReactDOM.createPortal inside of ReactDOM.render like this

ReactDOM.render(ReactDOM.createPortal(questionForm,questionPreview), document.createElement('div'));
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement