# JSX instead of h (createElement) function in widgets and other places

**URL:** <https://meta.discourse.org/t/jsx-instead-of-h-createelement-function-in-widgets-and-other-places/150040>\
**Category:** Development\
**Created:** [May 1, 2020, 9:46am UTC](https://meta.discourse.org/t/jsx-instead-of-h-createelement-function-in-widgets-and-other-places/150040 "2020-05-01T09:46:39Z")\
**Posts on this page:** 1\
**Showing post:** 1

<div class="post-metadata">

**Author:** ![zcuric](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/zcuric/32/292837_2.png) [@zcuric](https://meta.discourse.org/u/zcuric)\
**Post date:** [May 1, 2020, 9:46am UTC](https://meta.discourse.org/t/jsx-instead-of-h-createelement-function-in-widgets-and-other-places/150040/1 "2020-05-01T09:46:40Z")

</div>

Hi, I’ve been experimenting with JSX in widgets for better developer experience in themes (I’ve came up with my own setup for theme development without header.html etc, more on that in another topic).

I was wondering why doesn’t Discourse utilise babel plugins within the it’s codebase. In Discourse we have available `transform-react-jsx` babel plugin which can be used to transform JSX to custom createElement function using jsxPragma options. All of that is available in Discousre.

Adding `transform-react-jsx` here [https://github.com/discourse/discourse/blob/master/lib/discourse\_js\_processor.rb#L143-L149](https://github.com/discourse/discourse/blob/master/lib/discourse_js_processor.rb#L143-L149) and somehow exposing the Babel config to change the `jsxPragma` here [https://github.com/discourse/discourse/blob/master/vendor/assets/javascripts/babel.js](https://github.com/discourse/discourse/blob/master/vendor/assets/javascripts/babel.js)  
could make this happen.

I’ve already implemented the first part, the pragma part still needs some discovery. Unfortunately, there is no `.babelrc` to setup invidual plugin configuration. I get the `React.createElement` function instead of custom function.

More on using JSX without React here: [Using jsx WITHOUT React | r0b blog](https://blog.r0b.io/post/using-jsx-without-react/)

Any thoughts or maybe help how could this be achieved?

UPDATE:  
I did manage to make this work by changing the pragma setting in `vendor/assets/javascripts/babel.js` on line 26586

```js
var id = state.opts.pragma || "React.createElement";
// to
var id = state.opts.pragma || "h";

```

---

_[View the full topic](https://meta.discourse.org/t/jsx-instead-of-h-createelement-function-in-widgets-and-other-places/150040)._
