Skip to content
Advertisement

JSX with a HTML tag from a variable

I have a React component defined in JSX which returns a cell using either td or th, e.g.:

JavaScript

Would it be possible to write the JSX in such a way that the HTML tag is taken from a variable? Like:

JavaScript

The above code returns an error:

“unexpected token” pointing at {.

I am using Webpack with the Babel plugin to compile JSX.

Advertisement

Answer

Try setting your component state and rendering like so:

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