Closed espen42 closed 5 years ago
Any reason you cannot do this yourself with a lib?
Best reason: my XP-noob-ness so far.
But I'm thinking, if there's already an easy way, react is so popular and pleasant to work with (especially with CSS modules and ES6 support) that we might want to announce that more, eg. in courses etc?
The problem is that import React from 'react'; fails runtime in Nashorn.
Which got me started on render-js.
Here is my last attempt: https://github.com/ComLock/enonic-xp-starter-react https://github.com/ComLock/enonic-xp-starter-react/blob/master/src/main/resources/site/pages/react-page/react-page.jsx
The problem is polyfilling what react needs in a way that works in Nashhorn. It might be possible doing something like this: https://github.com/ComLock/enonic-xp-lib-autoprefixer/blob/master/webpack.3.server.config.babel.js#L111-L115
List of polyfills https://polyfill.io/v2/docs/features/
Have you solved this @ComLock?
My starter-react works in very simple examples, but I had troubles with it in a customer project.
What I have been able to do instead is provide JSX from a part controller and transpile it client-side using babel-standalone, and finally render it client-side using react and react-dom.
I have not made a clientSideJsx library for market, yet. But here is at least some example code https://github.com/ComLock/enonic-xp-starter-react/tree/master/src/main/resources/site/parts/clientSideJsx
What is happening with this issue? It has been in ready state in XP for a year but it is from what I understand a library.
@sigdestad @mortyeriksen Can you add this in backlog as a new library if necessary. Putting it back to PAB until then
I guess this will be solved by @espen42 in React4XP https://github.com/enonic?q=react4xp
Oh okay. Closing it then
Expanding the template support to React / JSX files, ideally supporting CSS modules and ES6 syntax.
Thymeleaf / mustache view templates (and controversially, XSLT) are all nice. But adding React support would be fashionable and popular with a lot of developers out there.
API-wise, it could behave much the same way as it already does (calling it
props
instead ofmodel
by convention, but it doesn't matter):Controller - hello.js:
View - hello.jsx:
Style - howdy.css:
etc.
It would also be nice if the JSX file didn't need the
import React from 'react';
line, but did that automatically. And ideally, it would also add a React.propTypes import as well:import React, {propTypes as PT} from 'react';
since those are handy and often used.