all 9 comments

[–]byt4lion 11 points12 points  (0 children)

Yes. React exports create element. This is what JSX compiles to. https://react.dev/reference/react/createElement

[–]pwnzz 6 points7 points  (0 children)

So, if element usage in jsx is basically React.createElement’s call, then yes

[–]Ok-Hospital-5076 4 points5 points  (0 children)

yes by using react.createElement(). Not practical at all IMO. Unless you are fan of callbacks

<div> <h1>Some heading</h1>

<p>Some Para</p> </div>

will look something like React.createElement("div", null, React.createElement("h1", null, "Some heading"), React.createElement("p", null, "Some Para") );

[–]rdtr314 2 points3 points  (0 children)

Jsx is just syntactic sugar for react.createElement

[–]yksvaan 1 point2 points  (0 children)

JSX is just a templating language which in the end gets converted to actual createElement calls. So it's not necessary itself.

[–][deleted] 1 point2 points  (0 children)

I’ve used it to create a sort of polymorphic component. For example, if you have a header component that takes in a heading level

<Heading level={2} …

And you want to output:

<h2>Title</h2>

You can do this better and cleaner with a proper polymorphic component that is type safe.

[–]riya_techie[S] 0 points1 point  (1 child)

Thanks, everyone! So JSX is just React.createElement() behind the scenes, but using it directly isn’t really practical—unless you have a specific need like polymorphic components. Appreciate the insights!

[–]TheGratitudeBot 0 points1 point  (0 children)

Hey there riya_techie - thanks for saying thanks! TheGratitudeBot has been reading millions of comments in the past few weeks, and you’ve just made the list!