Question
CNO
US
Last activity: 25 Mar 2019 23:18 EDT
How to use react in pega
is there step by step guide to use React in Pega.
-
Like (0)
-
Share this page Facebook Twitter LinkedIn Email Copying... Copied!
Pegasystems Inc.
US
In Pega 7.4, you can access Designer Studio -> User Interface -> Gallery -> UI Elements -> React components (under Extending your Pega UI section).
It shows how to integrate React components within the Pega Platform.
Pegasystems Inc.
Pega has included React JS bundle which you can use and create your own components.
<pega:onlyonce name="pega_ui_react">
The good part is you dont have to worry about building virtual dom, you can directly access all of the react fuctions.
All you need to is wherever you want to create a react js component or widget, create your jsx file which has the functionality and create a custom control and call this jsx file.
-
Wolfgang Radl Uttam Dutta
CNO
US
Thanks for the reply. Can you please give steps to use a basic hello world react script in a section.
Pegasystems Inc.
US
use the clock example as a starting point
- do a saveas of the custom control 'py_react_clock' to 'myhelloworld'
- remove JS include for the Moment JS libraries
- replace clock by our component name
The code would be like this:
<pega:choose>
<pega:when test="pxRequestor.pyPegaDesignMode != 'true'">
<!-- only include REACT JS once per page - use the bundle 'pzpega_ui_react_dev' for development and 'pzpega_ui_react' for production -->
<pega:onlyonce name="pega_ui_react">
<pega:static type="script" app="webwb">
<pega:bundle name="pzpega_ui_react" />
</pega:static>
</pega:onlyonce>
use the clock example as a starting point
- do a saveas of the custom control 'py_react_clock' to 'myhelloworld'
- remove JS include for the Moment JS libraries
- replace clock by our component name
The code would be like this:
<pega:choose>
<pega:when test="pxRequestor.pyPegaDesignMode != 'true'">
<!-- only include REACT JS once per page - use the bundle 'pzpega_ui_react_dev' for development and 'pzpega_ui_react' for production -->
<pega:onlyonce name="pega_ui_react">
<pega:static type="script" app="webwb">
<pega:bundle name="pzpega_ui_react" />
</pega:static>
</pega:onlyonce>
<!-- only include this component once per page - will not be reloaded on refresh -->
<pega:onlyonce name="myhelloworld">
<pega:static type="script" app="webwb">
<pega:file name="myhelloworldComponent.js"/>
</pega:static>
</pega:onlyonce>
<%
// Gen unique id for element
String uniqueId = "myhelloworld"+Long.toString(((com.pega.pegarules.priv.context.PegaRequestor) tools.getRequestor()).currentTimeUnique());
%>
<div id="<%= uniqueId %>" data-property="<pega:reference name="$this-name" mode="normal" />" data-type="myhelloworld">
</div>
<script>
ReactDOM.render(React.createElement(Myhelloworld, {'param1': 'value' }), document.getElementById("<%= uniqueId %>"));
/* Clear the state of the component on an Ajax Reload to set the setInterval ticker by calling the unmountComponentAtNode method function */
pega.u.d.registerAsHarnessElement({
nullify: function() {
ReactDOM.unmountComponentAtNode(document.getElementById("<%= uniqueId %>"));
}
}, pega.u.d.getSectionDiv(document.getElementById("<%= uniqueId %>")).getAttribute("uniqueID"));
</script>
</pega:when>
<pega:otherwise>
<span>Hello World component using ReactJS</span>
</pega:otherwise>
</pega:choose>
- do a saveas of the JSX file 'py_react_clock.js' to 'myhelloworldComponent.js' with the following content
class Myhelloworld extends React.Component {
render() {
return (
<div>
Hello world
</div>
);
}
}
2 things have to match between the custom control and the JSX component:
1/ the name of the component class 'Myhelloworld' should match the value in the custom control when doing
ReactDOM.render(React.createElement(Myhelloworld, {'param1': 'value' }), document.getElementById("<%= uniqueId %>"));
2/ the name of the JSX file should match
<pega:file name="myhelloworldComponent.js"/>
once you have built the control - make it available in the section by checking 'show in authoring menu' in the control "HTML" tab.
Then drop the control in your dynamic layout inside your section
-
Rishabh Prakash Abhi Falcao Uttam Dutta Diego Lievano
Tata Consultancy Services
IN
Hi Richard,
Is there any similar article for Angular js as well?
Please share link if it is available.
Regards,
Deepali
Hi Richard,
Is there any similar article for Angular js as well?
Please share link if it is available.
Regards,
Deepali