Developing React Widgets
This section describes how you can use React framework to develop your widgets.
#
Creating the Project#
About this taskYou can create a React Web Component widget. The following instruction provides an example of creating a my-web-comp widget.
note
If you use VS code, ensure that your typescript coming with VS code is v4.0.2 or higher.
#
Procedure- Create project structure running the following command in your terminal ⁄ console:
Navigate to the src directory in the project folder.
In the src directory, create a new empty .tsx component file. For testing purposes, you can create Welcome.tsx.
Add the following code to the Welcome.tsx file:
In the same directory, create a new .tsx file. For the purpose of this demo, you can create a MyWebComp.tsx file.
Import your Welcome React component into MyWebComp.tsx file and transform it into a customElement as follows:
#
Next stepWhen your project is ready as a Web Component, you must build it for later use.
#
Building the Project#
About this taskYou must build the project to use your widget in Avaya Workspaces.
note
If you use a different tool to build your React project or have a custom build setup, ensure your configuration aligns with the JSX transform in use.
Whether using the traditional import method or the new JSX transform, verify that your build configuration supports your chosen JSX approach. Refer to React documentation for details on JSX transform and build tool compatibility.
#
Procedure- In the root project folder, create the webpack.config.js file with the following contents:
- Add build scripts to the package.json file:
- Add tsconfig file with the following contents:
- Run the following command to install necessary packages:
- Build your project running the following command:
- The bundled file my-web-comp.js is in the dist folder. Host this folder using HTTP-server.
#
Next stepWhen your project is bundled and built, continue configuring the widget JSON file that you can import in the Widget Manager.