UNPKG

smh-rn-expo-json-ui-engine

Version:

A JSON-driven UI engine for React Native and Expo that enables dynamic, runtime-rendered interfaces without rebuilding the app.

1 lines 687 B
"use strict";import{Fragment,useEffect,useMemo,useState}from"react";import renderUIComponent from"./render.js";import{JSONUIEnums}from"./types.js";import{jsx as _jsx,Fragment as _Fragment}from"react/jsx-runtime";const isObservable=e=>!!e&&"function"==typeof e.subscribe,JSONUI=({json:e,jsonSource:r})=>{const[s,t]=useState(e||[]);useEffect(()=>{if(isObservable(r)){const e=r.subscribe(t);return()=>e.unsubscribe()}return()=>{}},[r]);const n=useMemo(()=>isObservable(r)?s??[]:"function"==typeof r?r():r||(e??[]),[e,r,s]),o=Array.isArray(n)?n.map((e,r)=>_jsx(Fragment,{children:renderUIComponent(e)},r)):renderUIComponent(n);return _jsx(_Fragment,{children:o})};export{JSONUI,JSONUIEnums};