Ever wondered how apps like Flipkart or Blinkit update their homepages without an app update?
It's all possible thanks to Server-Driven UI (SDUI).
๐ง What Is Server-Driven UI?
Instead of hardcoding the UI in the app, you fetch a JSON configuration from the backend that describes the UI layout and components. The app then renders components dynamically based on this data.
๐ฆ Sample JSON
{
"type": "VerticalLayout",
"children": [
{
"type": "Banner",
"image": "https://example.com/banner.jpg",
"action": {
"type": "navigate",
"target": "ProductScreen",
"params": { "id": "1234" }
}
},
{
"type": "ProductCarousel",
"title": "Top Deals",
"products": [
{"id": 1, "title": "Item A"},
{"id": 2, "title": "Item B"}
]
}
]
}
๐ ️ Renderer Example in React Native
const handleAction = (action) => {
if (action?.type === 'navigate') {
navigation.navigate(action.target, action.params);
}
};
const renderComponent = (component) => {
switch (component.type) {
case 'Banner':
return (
handleAction(component.action)}>
);
case 'ProductCarousel':
return (
{component.title}
{item.title} }
/>
);
case 'VerticalLayout':
return (
{component.children.map((child, index) => (
{renderComponent(child)}
))}
);
default:
return null;
}
};
๐ Navigating from JSON Components
You can define navigation actions directly in JSON using a consistent contract. The renderer interprets and executes those using React Navigation.
{
"type": "button",
"title": "Shop Now",
"action": {
"type": "navigate",
"target": "ShopScreen",
"params": {
"category": "electronics"
}
}
}
Your app should support a universal handleAction
method that handles navigation, deep links, modals, and other behaviors as per the JSON definition.
⚙️ How It Works: Flow Diagram
- ๐ฒ App starts
- ๐ Fetches UI schema JSON from server
- ๐ง Parses JSON and maps it to UI components
- ๐ Attaches actions like navigation based on JSON
- ๐ฆ Re-renders UI on schema change without needing app updates
✅ Benefits
- Real-time updates without app releases
- Backend A/B testing of layouts
- Dynamic navigation powered by backend logic
๐จ Challenges
- Initial setup takes time
- Need strong backend + caching strategy
- Validation, type safety & fallback handling required
๐งช Real-World Use Cases
App | Use Case |
---|---|
Flipkart | Home screen banners, carousels, deals |
Blinkit | Dynamic categories, offers, seasonal content |
Netflix | Category rows like Trending, New Releases |
๐ Best Practices
- Design a component contract between backend and frontend
- Support standardized action types like navigate, modal, toast
- Use TypeScript types/interfaces to validate JSON schema
- Set up fallback UI for unknown types or errors
- Cache schema locally to improve performance
๐ Conclusion
Server-Driven UI is future-ready — giving you flexibility, speed, and control over content. Adding action management like navigation brings dynamic interactivity with no need for manual updates.
๐ Tip: Combine with React Navigation,Redux or Context to manage global state across JSON-defined views.
Comments
Post a Comment