RE: What is the best solution for React-based UI's?

Matt Kruse, modified 5 Years ago. New Member Posts: 14 Join Date: 11/6/19 Recent Posts
Let's say I want to create a number of components that are purely front-end, using React. They will retrieve data from an API and render it.What is the best solution in Liferay to enable developers to build and deploy these front-end-only interfaces?The only reference I have found is details on coding a Portlet, compiling, etc. I do not want to do all of this, because React is purely front-end, and I don't want to introduce all this back-end work to use a simple component.What's the best solution?
thumbnail
Christoph Rabel, modified 5 Years ago. Liferay Legend Posts: 1555 Join Date: 9/24/09 Recent Posts
Liferay has some nice infrastructure for that. Basically, you create the react app, use a little Liferay called liferay-js-generator tool to "name & package" it and use it in Liferay. (Or you create it directly with the generator)
There was a presentation about that on Devcon a few days ago, the presentation explains the steps.
https://www.liferay.com/documents/231927853/238977089/D1_A_06+-+The+Frontend+Developer%27s+Guide+to+the+Galaxy+-+Rodolfo+Miranda+%26+Carlos+Lancha.pdf/df656248-3135-3075-60ff-561fffebc5bd?t=1574184372619
Here's the repository with the code:
https://github.com/carloslancha/spaceship-react
Matt Kruse, modified 5 Years ago. New Member Posts: 14 Join Date: 11/6/19 Recent Posts
This looks like it's still building a portlet that needs to be deployed to Liferay. Seems like over-kill for a front-end-only solution, doesn't it?I'm experimenting with including React into the theme, and then building React (or Vue) Components directly into a Fragment. This seems like a more sane approach than toolkits and generating portlets.
thumbnail
Olaf Kock, modified 5 Years ago. Liferay Legend Posts: 6441 Join Date: 9/23/08 Recent Posts
Without being too much in the Frontend world myself: Isn't the portlet just a generic portlet that can be configured with any react app? As Liferay, in its root, combines different portlets to a common UI anyway, this doesn't seem too bad, especially when there's a generic portlet for all react apps. Yes, it could be in Fragments as well, but wouldn't that mix apps and content?
Note: this is neither positive nor negative, just an alternative way to look at it. I'm typically distancing myself from the frontend as much as I can - others are quicker to produce nice results.
This is also nitpicking of the "best solution" question, where I can't resist asking back: "Best for what?" In the end, the various solutions won't be too far away from each other.
thumbnail
Christoph Rabel, modified 5 Years ago. Liferay Legend Posts: 1555 Join Date: 9/24/09 Recent Posts
Well, I am not sure about that.  Portlets bring a nice set of features with them and it is a pretty sane approach to bundle a new component into a portlet, to take advantage of those features. On the other hand, from a developers point of view, you care about getting your component (be it React, Angular, vue, ...) into Liferay *without* the need to know a lot about it.
Honestly speaking, do you really care that a portlet provides your React module to Liferay instead of a "ReactComponentProvider" (a thing, I made up just now)?
That said, I have used a different approach before. We have our own webpack bundler, you can find a few things about it here.
https://liferay.dev/blogs/-/blogs/developing-javascript-frontends-with-webpack
But I am actually thinking about moving into the Liferay direction, I hear the fragment builder will support npm in future versions too. The big advantage of webpack is hot reload, but the bundler/loader of Liferay allows me to create microfrontends. And that's also very neat.
thumbnail
Jack Bakker, modified 5 Years ago. Liferay Master Posts: 978 Join Date: 1/3/10 Recent Posts
I am exploring decoupled 'pure?' front-end pwa (lit-html based building for modern/legacy browsers using open-wc) where the front-end app interfaces with the new Liferay v7.2 GraphQL apis (https://liferay.dev/blogs/-/blogs/new-graphql-apis-in-liferay-7-2). In js I am using https://github.com/gucheen/FetchQL because it has es module support which saves me much webpack/rollup plugin hassles. For a React front-end app: GraphQL using apollo client is likely a good choice. I currently am just kicking the tires of the new GraphQL support in Liferay, but so far it looks pretty darn 'cool' and should only get better.
thumbnail
Christoph Rabel, modified 5 Years ago. Liferay Legend Posts: 1555 Join Date: 9/24/09 Recent Posts
The new headless APIs are certainly useful in that regard, but you also lose a lot of the features. So, it is a tradeoff. I probably won't use it to fetch "full pages" in the near future, but we already used it to fetch news from one system to show it on another one. They are certainly useful and I am really glad that that approach is possible now with the newer Liferay versions.
thumbnail
Jack Bakker, modified 5 Years ago. Liferay Master Posts: 978 Join Date: 1/3/10 Recent Posts
yeah, up to the frontend app to construct the so-called 'page' (view) built including using 'stuff' it might get through the api ; I think that is to be expected/preferred in decoupled frontend from backend