import React from "react"; import useShape from "../../ng-mock/js-land/frontendAdapters/react/useShape"; import flattenObject from "../utils/flattenObject"; import { TestObjectShapeType } from "src/shapes/ldo/testShape.shapeTypes"; export function HelloWorldReact() { const state = useShape(TestObjectShapeType); // @ts-expect-error window.reactState = state; if (!state) return <>Loading state>; // Create a table from the state object: One column for keys, one for values, one with an input to change the value. return (
Rendered in React
Key | Value | Edit |
---|---|---|
{key} | {value instanceof Set ? Array.from(value).join(", ") : Array.isArray(value) ? `[${value.join(", ")}]` : JSON.stringify(value)} |
{typeof value === "string" ? (
{
setNestedValue(state, key, e.target.value);
}}
/>
) : typeof value === "number" ? (
{
setNestedValue(state, key, Number(e.target.value));
}}
/>
) : typeof value === "boolean" ? (
{
setNestedValue(state, key, e.target.checked);
}}
/>
) : Array.isArray(value) ? (
|