question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Allowing <{element}></{element}> in JSX to render a variable element

See original GitHub issue

You can now write almost anything in JSX that you can write in JavaScript…except for this case, as far as I can tell. Instead of having to write:

React.createElement(someDynamicElement, props, children)

I think it would be neat to be able to write:

 <{someDynamicElement} {...props}>
   {children}
 </{someDynamicElement}>

It’s not a huge deal, but it would plug the last leak in JSX syntax, allowing people to not have to do a context switch and think about the underlying transform in order to figure out how to do something like this.

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Reactions:1
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

4reactions
zpaocommented, May 19, 2015

Yea, this works since we’ll just pass whatever is there along to createElement. You can even have a variable that is a string and a DOM component will be created. The point about capitalizing is important.

var D = 'div';
return <D {...props}/>
1reaction
cmwelshcommented, May 19, 2015

You need to uppercase it so React knows it’s not an HTML element.

Read more comments on GitHub >

github_iconTop Results From Across the Web

JSX In Depth - React
Specifying The React Element Type. The first part of a JSX tag determines the type of the React element. Capitalized types indicate that...
Read more >
how to store jsx element to javascript variable - Stack Overflow
I tried adding ' ' for the div but not getting element properly. It is returing as string. Can someone explain me the...
Read more >
Return a Variable in the Render Function in React | Pluralsight
Using JSX, you can create a function and return a set of JSX elements to a variable, and that variable used is to...
Read more >
How To Create React Elements with JSX - DigitalOcean
JSX is an abstraction that allows you to write HTML-like syntax in your ... For example, you can't make a variable called null...
Read more >
Documentation - DOM Manipulation - TypeScript
It serves as the base interface for every other element interface. For example, the p variable in the code example is of type...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found