How can I import Liferay Portal library to my react project?

Jamie Sammons, muokattu 3 Vuodet sitten. New Member Viestejä: 6 Liittymispäivä: 9.3.2023 Viimeisimmät viestit

Hello everyone, i would like to use the command Liferay.ThemeDisplay in my react application but if i try to install the library liferay-portal or frontend-js-web with npm I get errors, so i tried to install directly from github with the command npm install https://github.com/liferay/liferay-portal but is still not working.

I searched on the net and the library that i have to use should be this one, so how can i add to my react application?


Thanks everyone.

thumbnail
Jamie Sammons, muokattu 3 Vuodet sitten. Liferay Legend Viestejä: 1555 Liittymispäivä: 24.9.2009 Viimeisimmät viestit

The Liferay object is added to all Liferay pages as a global variable, so you should be able to just access it directly when your React application is added to a Liferay page. No need to import anything.

Jamie Sammons, muokattu 3 Vuodet sitten. New Member Viestejä: 6 Liittymispäivä: 9.3.2023 Viimeisimmät viestit

I've already tried to use it without import anything but it didn't work. I have the error 'Liferay’ is not defined that's why i thought i had to import something. How can I solve this error? Thanks.

thumbnail
Jamie Sammons, muokattu 3 Vuodet sitten. Liferay Legend Viestejä: 14933 Liittymispäivä: 2.9.2006 Viimeisimmät viestit

Try using window.Liferay.ThemeDisplay.

Jamie Sammons, muokattu 3 Vuodet sitten. New Member Viestejä: 6 Liittymispäivä: 9.3.2023 Viimeisimmät viestit

Already tried, still not working unfortunately.

Jamie Sammons, muokattu 2 Vuodet sitten. New Member Viestejä: 6 Liittymispäivä: 8.2.2023 Viimeisimmät viestit

Hi Gregorio,

in Liferay Github you can find some examples how it works. As I unterstand you try to run something like coded in this client extension:

https://github.com/liferay/liferay-portal/tree/master/workspaces/liferay-sample-workspace/client-extensions/liferay-sample-custom-element-2