Ask Questions and Find Answers
Important:
Ask is now read-only. You can review any existing questions and answers, but not add anything new.
But - don't panic! While ask is no more, we've replaced it with discuss - the new Liferay Discussion Forum! Read more here here or just visit the site here:
discuss.liferay.com
RE: What is the best solution for React-based UI's?
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?
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
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
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.
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.
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.
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.
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.
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.
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.
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
Copyright © 2025 Liferay, Inc
• Privacy Policy
Powered by Liferay™