import { createContext , useContext , useMemo , useCallback } from 'react' ; export type VarUIObject = any ; export interface IVarUIContext { values : VarUIObject ; getValue : ( path ? : string ) => any ; setValue : ( path : string , value : any ) => void ; } export const VarUIContext = createContext < IVarUIContext | undefined > ( undefined ) ; param path param fallbackValue param onChange returns export function useVarUIValue < T > ( path ? , fallbackValue ? , onChange ? ) { const context = useContext ( VarUIContext ) ; const value = useMemo ( ( ) => context ?. getValue ( path ) ?? fallbackValue , [ context , path , fallbackValue ] ) ; const setValue = useCallback ( ( value ) => { if ( path && context ) { context . setValue ( path , value ) ; } onChange ?. ( value ) ; } , [ path , context , onChange ] ) ; return [ value , setValue ] ; }