How to Add a React Report Viewer to Your Web Application
Tags: javascript, webdev, tutorial, devops
Published: 2022-09-26 15:34:37

---
canonical_url: https://developer.mescius.com/blogs/how-to-add-a-react-report-viewer-to-your-web-application
description: Learn how to add a React report viewer to your web application. See more from ActiveReports today.
---
ActiveReportsJS is a client-side reporting solution that can be used in a variety of different front-end frameworks and libraries. From vanilla JavaScript to NuxtJS, ARJS is extremely flexible when designing your application and using its components.

In this article, we’ll break down how to add and customize the Report Viewer component in your React application. We’ll be covering the following steps:

1.  [Installing the Dependencies](#install)
2.  [Importing the Styles](#import)
3.  [Creating a Report File](#create)
4.  [Integrating the Viewer Component to our App](#integrate)
5.  [Running the Application](#run)

### <a id="install"></a>Installing the Dependencies

First, you’ll need to create a React application; to create one, run the following command:

```
    npm install @grapecity/activereports-react
```

Once you’ve created your React application, we’ll need to install the ActiveReportsJS React package. We’ll be using NPM to install ActiveReportsJS. To do so, run the following command:

```
    npm init react-app arjs-viewer-app
```

### <a id="import"></a>Importing the Styles

Once we’ve installed the React packages, we can import the ActivReportsJS Report Viewer styles files. We’ll also style a div element that we’ll use to host the Report Viewer component:

```
    @import "@grapecity/activereports/styles/ar-js-ui.css";
    @import "@grapecity/activereports/styles/ar-js-viewer.css"; 

    #viewer-host {
      width: 100%;
      height: 100vh;
    }
```

### <a id="create"></a>Creating a Report File

Next, we’ll need to add an ActiveReportsJS report file to our application. For the purposes of this demo, we’ll manually create a report, however you can feel free to use a report created with the Report Designer component.

Since ActiveReportsJS reports use the .rdlx-json extension, we can format the properties and controls of the report via JSON syntax. Add a new file to your application’s public folder and name it **report-text.rdlx-json**. Within that file, add the following JSON:

```
    {
      "Name": "report-test",
      "Body": {
        "ReportItems": [
          {
            "Type": "textbox",
            "Name": "TextBox1",
            "Value": "Testing the textbox!",
            "Style": {
              "FontSize": "20pt"
            },
            "Width": "8.5in",
            "Height": "1.5in"
          }
        ]
      }
    }
```

This will create a report that contains a textbox that reads “Testing the textbox!”.

If you’d like information on creating a report through our API, look deeply at our documentation [here](https://developer.mescius.com/activereportsjs/api/modules/Core.Rdl#report "https://developer.mescius.com/activereportsjs/api/modules/Core.Rdl#report") to see what can be added to a report at runtime.

### <a id="integrate"></a>Integrating the Viewer Component to our App

Now, in the App.js file, let’s add the following code to get the viewer component to show on our page. This will also link the report we just made to our viewer component.

```
    import React from "react";
    import "./App.css";
    import { Viewer } from "@grapecity/activereports-react";

    function App() {
      return (
        <div id="viewer-host">
          <Viewer report={{ Uri: 'report.rdlx-json' }} />
        </div>
      );
    }

    export default App;
```

Here, we import the **Viewer** component from the ActiveReportsJS React module. We then initialize it in markup, and bind the report that we created to the **report** property.

### <a id="run"></a>Running the Application

Occasionally, we will encounter an error that blocks us from using ‘npm start’ while debugging our project. To fix this, change the start script in the package.json file to the following:

```
    "start": "react-scripts --max_old_space_size=8192 start"
```

Run the project with the ‘npm start’ command in the terminal. If all goes well, you will see the viewer component on your page and the report file embedded within it. If you run into further issues or errors, please open a [ticket](https://developer.mescius.com/support/contact "/support/contact") with our support team for more assistance.

### Theme Editor

If you want to customize the report viewer's colors, fonts, and themes, you can do so by using the theme editor found [on our website](https://developer.mescius.com/activereportsjs/theme-editor/ "https://developer.mescius.com/activereportsjs/theme-editor/"). Select which settings you’d like to use and preview the viewer component on our page. Once you find a theme you love, download the CSS styles from the button at the bottom of the page. Afterward, move the files into the styles folder within your application (node_modules/@grapecity/activereports/styles) to overwrite the default viewer theme. If you would rather use pre-created themes, there is a wide selection that you can learn about [here](https://developer.mescius.com/activereportsjs/docs/DeveloperGuide/ActiveReportsJSViewer/Themes "https://developer.mescius.com/activereportsjs/docs/DeveloperGuide/ActiveReportsJSViewer/Themes").

![Theme Editor](//cdn.mescius.io/umb/media/eymblani/theme-editor.gif?width=500&height=321.42857142857144)

### Final Points

After following the steps in this walkthrough, you should now be able to add the React Report Viewer component to your application. The viewer will be great for your reporting needs, given the [rich API](https://developer.mescius.com/activereportsjs/api/classes/ReportViewer.Viewer "https://developer.mescius.com/activereportsjs/api/classes/ReportViewer.Viewer"), [customization techniques](https://developer.mescius.com/activereportsjs/docs/DeveloperGuide/ActiveReportsJSViewer/Customization "https://developer.mescius.com/activereportsjs/docs/DeveloperGuide/ActiveReportsJSViewer/Customization"), and [language translation](https://developer.mescius.com/activereportsjs/docs/DeveloperGuide/ActiveReportsJSViewer/Localization "https://developer.mescius.com/activereportsjs/docs/DeveloperGuide/ActiveReportsJSViewer/Localization") options that ARJS provides. If you have questions regarding more complex use cases, please read through our [documentation](https://developer.mescius.com/activereportsjs/docs/GettingStarted/Introduction "https://developer.mescius.com/activereportsjs/docs/GettingStarted/Introduction").

Thanks for using ActiveReportsJS!