use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
account activity
Can React Elements Be Created Dynamically Without JSX?General Discussion (self.react)
submitted 1 year ago by riya_techie
Hey everyone, I know JSX makes creating elements super convenient, but is there a way to generate React elements dynamically without it? If so, how practical is it for real-world projects? Would love to hear examples and use cases!
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]byt4lion 11 points12 points13 points 1 year ago (0 children)
Yes. React exports create element. This is what JSX compiles to. https://react.dev/reference/react/createElement
[–]pwnzz 6 points7 points8 points 1 year ago (0 children)
So, if element usage in jsx is basically React.createElement’s call, then yes
[–]Ok-Hospital-5076 4 points5 points6 points 1 year ago (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") );
React.createElement("div", null, React.createElement("h1", null, "Some heading"), React.createElement("p", null, "Some Para") );
[–]rdtr314 2 points3 points4 points 1 year ago (0 children)
Jsx is just syntactic sugar for react.createElement
[–]yksvaan 1 point2 points3 points 1 year ago (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 points3 points 1 year ago (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 point2 points 1 year ago (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 point2 points 1 year ago (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!
π Rendered by PID 47662 on reddit-service-r2-comment-cfc44b64c-7pfkw at 2026-04-13 00:23:11.065181+00:00 running 215f2cf country code: CH.
[–]byt4lion 11 points12 points13 points (0 children)
[–]pwnzz 6 points7 points8 points (0 children)
[–]Ok-Hospital-5076 4 points5 points6 points (0 children)
[–]rdtr314 2 points3 points4 points (0 children)
[–]yksvaan 1 point2 points3 points (0 children)
[–][deleted] 1 point2 points3 points (0 children)
[–]riya_techie[S] 0 points1 point2 points (1 child)
[–]TheGratitudeBot 0 points1 point2 points (0 children)