It's a structure format that defines everything from the layout of components to the interactions. When the server sends a schema to the client via an API, it's not only a set of vague instructions. It's a detailed map that guides us how the UI structure. The schema specifies what components to use, where to place them, how they should appear, how they should behave when the user interacts.
Next are the React components. In the SDUI architecture, React components are designed to be flexible and responsive to the schema provided by the server. The beauty of this setup is that the UI logic is no longer hard-coded into the client-side code. Instead, it's dynamically driven by the server, making the UI extremely adaptable to the change without requiring constant redeployments.
So how does it all come together? The server sends a schema which acts as a guide and the React renders the UI based on that schema, providing both structure and interactivity.
Now, enough talk. Let's dive into a demo. To avoid any last-minute server issues, which tends to happen a lot with me, I've pre-recorded the demo for you. Let's take a look at how the SDUI works in action.
In this demo, I'll walk you through the simple website built with React on the front end and Node.js with Express on the back end. First, let's look at the back end. Here we define the UI schema. The schema outlines various components like header, product list, banners, and footers, along with properties that control appearances and content. For this, we are using Express.js to create a server that dynamically serves these UI configurations. The schema is sent to the front end via the POST API.
On the front-end side, we can fetch the UI configuration from a back-end and dynamically render the corresponding components. I've structured the components in separate files to make them modular and reusable, aligning with the React's component-based architecture. Here's the website you can see, rendered with the content and data directly driven by the schema.
Now, let's make a change. Suppose we want to update the banner. We want to update the banner to display it like the last day for the offer, and also want to change the color to green. Instead of modifying the front-end code, we'll just update the schema here at the back end. When you have it, and there you have it. With a simple change to the schema, the UI is updated without touching the front-end code.
So, that was a quick demo. In case you want to look at the code, you can visit this GitHub repository.
Comments