How to Use Wijmo Controls in ReactJS Apps

Here's a quick introduction on how to use Wijmo controls in your ReactJS applications. As of Build 207, Wijmo officially supports ReactJS.

What is React?

React is Facebook's library for building user interfaces in JavaScript. React is unique and incredibly popular, so we won't spend any time discussing its details here. If you're interested in a quick introduction to React and a comparison between it and other frameworks and libraries, here's a great article on that topic: Angular 2 versus React.

How is React different from Angular?

React is not a full framework but “a JavaScript library for building user interfaces”. It's very different from Angular and most typical JavaScript frameworks.

Instead of adding support for custom tags and attributes in HTML markup, it builds and maintains virtual document trees, and synchronizes those with the browser’s actual DOM when necessary. The virtual trees are created using JavaScript or JSX (a JavaScript syntax extension that makes JavaScript look like HTML).

React uses components that manage their own state. Building complex UIs is a matter of composing components. Component logic is written in JavaScript (instead of templates), so you can keep your data intact through the entire app.

The application creates two components and renders the main one on the browser.

The script is written in JSX, which is transpiled into JavaScript on-the-fly using babel. This conversion could also be performed off-line during the build process.

One of the main ideas behind React is that of keeping a copy of the DOM using their own data structures. React applications work against this copy, and React takes care of applying the changes to the actual DOM. This can result in performance gains because React computes the differences between the DOMs and is smart about applying the changes.

Because React creates its own version of the DOM, using its own components, they can bypass the browser entirely and render the document themselves. This is the idea behind React Native, which can be used to create native applications for IOS and Android. Of course, if you choose that route then you won’t be able to use Wijmo or any other libraries that rely on “real” HTML.

How to use Wijmo in React applications

To use Wijmo in your React applications, start by adding references to React and Wijmo to your page, and then include the “wijmo.react.js” module which defines components that wrap the Wijmo controls. For example:

The syntax is typical of JSX/React, and quite different from HTML/Angular.

Component and property names contain no hyphens (JSX is ultimately JavaScript). Values assigned to properties may be literals (enclosed in quotes) or they may be JavaScript values (enclosed in curly brackets).

In this example, we are setting the grid’s columns property to an array containing items with the column properties. There’s no need for special components to define grid columns.

This example is interesting because it shows how to implement two-way binding. The text property of the ComboBox is automatically set when the current item changes. This is standard one-way binding, built-into React and the component.

When the user edits the text, the ComboBox does not automatically apply the new value to the bound data object. Instead, the component must handle the textChanged event and apply the new value itself. In this case, this is handled by the “nameChanged” method in the App component (which is the component that contains the ComboBox):