Dynamic User Profile Example
Building a user profile UI with asynchronous data fetching
This example demonstrates how to create a dynamic user profile UI that fetches user data asynchronously and renders different content based on the user's role.
Components
First, let's define our custom components for the user profile:
Registry and Event Handlers
JSON Definition
Async Data Fetching Plugin
The key part of this example is a plugin that fetches user data and updates the JSON:
Complete Example
Here's how to put it all together:
The real power of this approach is that the UI structure is determined at runtime based on data. Different user roles can see completely different interfaces without additional code.
Key Points
- Async Data Fetching: The
UserDataPlugin
fetches data and completely transforms the UI based on the response - Conditional Rendering: Admin users see an additional AdminPanel component
- Dynamic Children: The plugin replaces the initial loading message with actual content
- Clean Separation: The UI structure is defined in JSON, separate from data fetching logic
This pattern is particularly useful for dashboards or user interfaces that vary significantly based on user roles, permissions, or other dynamic data.