import React, { useContext } from 'react' import { tersify } from 'tersify' import { mapKey } from 'type-plus' import type { JustReactApp } from '../contexts/just_app_context.js' import { useJustAppContext } from '../hooks/use_just_app_context.js' import { Card } from './card.js' /** * AppInfo is a generic component not tied to any specific app. * * Typically, generic component can get the app through props. * We can also use context to get the closest gizmo/app. */ export function AppInfo({ app, title }: { app?: JustReactApp; title?: string }) { const appFromContext = useJustAppContext() if (!app) app = appFromContext return ( {title &&

{title}

}

The app contains the following info:

{mapKey(app, (key) => (

{key}: {tersify(app![key], { maxLength: 50 })}

))}
) } export function AppInfoWithUseContext({ context, title }: { context: React.Context; title?: string }) { const app = useContext(context)! return ( {title &&

{title}

}

using useContext()

The app contains the following info:

{mapKey(app, (key) => (

{key}: {tersify(app![key], { maxLength: 50 })}

))}
) } export function AppInfoWithUseJustAppContext({ context, title }: { context: React.Context; title?: string }) { const app = useJustAppContext(context) return ( {title &&

{title}

}

using useJustAppContext()

The app contains the following info:

{mapKey(app, (key) => (

{key}: {tersify(app![key], { maxLength: 50 })}

))}
) }