+ 3

ReactDOM.render on class div ?

Hi, i'm currently learning React and came to the subject of functional components and class components. As in the example, a div with an id is used, i wanted to try the same thing on multiple div elements (placed in an index.html file) with a common class name. Thing is, it doesn't work. I want to understand why, how React work in those cases, and finally, how to do it. Here's the code that i made : class Ok extends React.Components { render() { return <h3>Bonjour !</h3>; } } var hello = <Ok />; ReactDOM.render(hello, document.getElementsByClassName('test')); Thanks for your help ;-)

13th Jul 2021, 3:07 PM
Sumpheus
Sumpheus - avatar
2 odpowiedzi
+ 1
https://stackoverflow.com/questions/56789532/react-render-inside-class-tag-instead-id/56789835 ReactDOM.render() expect single element but with className you got array of elements, thats why is not working.
13th Jul 2021, 10:42 PM
PanicS
PanicS - avatar
0
I see, thanks 👍
14th Jul 2021, 11:02 PM
Sumpheus
Sumpheus - avatar