Skip to content
Advertisement

HTMLImageElement not valid as a React Child

I’m trying to load an image asynchronously and only when it’s been loaded, display it in a React app.

JavaScript

I’m getting below error:

Objects are not valid as a React child (found: [object HTMLImageElement])

I would like to know why this error is happening. Of course if I just add an <img> tag, it works fine.

Advertisement

Answer

React cannot directly display HTML Element. If you want to create elements programmatically you have to use functions provided by React.

JavaScript

React parses jsx element like div, img, HelloWorld (custom) etc. and create React Elements out of it.

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement