Config Driven UI using ReactJS

Spanish audio is available in the player settings
Rate this content
Bookmark
Slides

We at Microsoft are rethinking the way we use ReactJS as frontend devs, traditional React UI Design patterns results in redundant code, making code maintainability cumbersome. By making UI Config driven we supercharged React components by making config file a single source of truth, The above approach made it easier to onboard new UI scenarios quickly and with minimal regression in the old UI Flows, resulting in a significant reduction in dev efforts, the best part is all the code was kept in Typescript only no XML or other declarative languages were used.

FAQ

Config-driven UI in ReactJS is a technique that allows developers to create user interfaces based on a configuration file, such as JSON or TypeScript. This file defines the layout and content of the UI components, enabling dynamic and customizable interfaces without hard coding them.

Config-driven UI simplifies UI development by allowing changes through modifying a JSON file rather than altering code directly. This streamlines the process, makes it easier to manage and update UI components, and enables reusability of components across different pages or scenarios.

The key components include a base UI layer, elements (leaf nodes like dropdowns or charts), and containers like vertical and horizontal stacks. These components are defined in a configuration file, which is parsed and rendered using a custom React component.

In a config-driven UI, the layout configuration typically includes elements and their arrangement in vertical or horizontal containers. These containers can be nested to create complex layouts, with properties such as 'type' and 'children' defining the structure and hierarchy.

The layout-renderer component in ReactJS takes a JSON configuration file as a prop, parses it, and uses React hooks to recursively render UI components based on the layout specified in the configuration. It handles both vertical and horizontal elements to construct the UI dynamically.

In config-driven UI, changes to the user interface are managed by modifying the configuration file rather than the source code. This allows developers to update or adapt the UI quickly by just altering the configuration settings, enhancing flexibility and scalability.

Benefits include increased flexibility in UI design, faster iterations, easier maintenance and updates, reusability of components, and the ability to dynamically adapt the UI for different scenarios or user requirements without deep changes to the underlying code.

Joban Singh
Joban Singh
7 min
06 Jun, 2023

Comments

Sign in or register to post your comment.

Video Summary and Transcription

This lightning talk introduces config-driven UI in ReactJS, a technique for creating dynamic and customizable UIs without hard coding. It covers the implementation of different types of components and how they can be nested to create complex layouts.

1. Introduction to Config-Driven UI in ReactJS

Short description:

Hello, everyone, and welcome to a lightning talk on config-driven UI using ReactJS. Config-driven UI is a technique that allows you to create dynamic and customizable UIs without hard coding them. It uses a configuration file to define the layout and content of the UI components. This talk will cover the implementation of a smallest unit of component, such as a drop-down, form, or chart.

Hello, everyone, and welcome to a lightning talk on config-driven UI using ReactJS. In this video, I'll explain what config-driven UI means and how we can do it in ReactJS.

But first, a brief intro about me. So hey, guys, I'm Joban. And I've been working at Microsoft for the past two years. And you guys can reach out to me on the below handles. And so without further ado, let's get started.

So what is config-driven, right? What it means. Config-driven UI is a technique that allows you to create user interfaces based on a configuration file, such as JSON, or a TypeScript file that defines the layout and content of the UI components. This can be useful for creating dynamic and customizable UIs without hard coding them.

For example, let's say you want to create a dashboard that shows different types of data visualizations and summaries. Instead of writing GSX code for each component and arranging them in a fixed layout, you can use a JSON file that specifies the type, size, position, and data source for each component. And then you can create a custom component that reads that JSON file and renders the UI accordingly. So this way you can easily change the UI by modifying the JSON file without even touching the other code. You can also reuse the same component from different pages and all for different scenarios by providing different JSON files.

Moving on, now let's understand this a bit in detail. So here we can see a base UI layer on top of which there is a kind of a wizard menu which consists of various tiles number 1, number 2, number 3, etc. And each tile has a bunch of components A, B, C, etc. The V and the H on the left side you can see, it represents whether the layout setting of each component is whether it is a horizontal or a vertical component. We will come to that what it means.

Now for the tile 2 we can have a very similar UI as tile 1 with slight change in the component layout. You can see here. Similarly for tile number 3 also has minor differences in the UI. Now the idea here is do not create separate files for each tile as the UI differences are very minor, but to have a single config file for all the tiles and we render the tiles on the go by reading the config. So how can we do this in reactjs. There are many ways to implement to be honest this config driven UI paradigm. But in this talk, I will show you one of the possible approaches using react-hook and custom components. The basic idea is to have two parts. One to define the layout which uses a recursive structure to hold vertically and horizontally stacked elements and another to map leaf nodes to the actual content that needs to be displayed. In this talk, we will cover the actual implementation of a smallest unit of component, for example, a drop-down, it can be a form, it can be a chart.

2. Layout Part Overview

Short description:

The layout part consists of three types of components: element, vertical, and horizontal. Elements represent single UI components, while vertical and horizontal containers allow for stacking elements in different directions. These containers can be nested to create complex layouts. The components are defined using properties such as type, config, and children.

Let's start with the layout part. On the screen, you can see the layout part consists of three types of components. The first is element, and then vertical and horizontal. Element is the leaf node that represents a single UI component such as a drop-down chart and the form as I already said. Vertical and horizontal are containers on top of those elements, which allows us to stack elements either vertically or horizontally. It provides us that information. These containers can also be nested inside each other to create complex layouts. The type property specifies the type of the component. The config property contains an ID property as well, which uniquely identifies the component. The other properties that help you to draw the component. The children property is an array of child nodes that follow the same format to create nested UIs.