Skip to content
Advertisement

Can I write HTML tags inside of a React code?

Sorry I’m newbie to React. It might be a stupid question but can I write HTML code inside of a React code? I’m trying to make a custom block for my wordpress theme and found a example code of JavaScript.

JavaScript

I inserted some div tags and p tags inside of the code like HTML, but keeps giving me error. I think I need to study it later LOL

Advertisement

Answer

Well, it is kind of tricky question. The problem that you cannot use HTML directly in React js files. To make things working you need to have a babel compiler that will replace you HTML tags with React objects.

The code you’ve sampled it using compiled code (React.createElement). You have to pass this data as a child of some react component to make it work.

So or you using enter link description here or use Babel compiler to prepare your code.

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