import { PropsWithChildren, ReactElement, useEffect, useState } from 'react'; import { TextField } from '@fluentui/react'; import React from "react"; import { IFormItem, IPropertyRenderProps, json, IDynamicJsonFieldConfig } from '@wiberg/formbuilder'; interface IProps extends IPropertyRenderProps, string | undefined> { config?: IDynamicJsonFieldConfig; } export const DynamicJsonfield = (props: PropsWithChildren>) : ReactElement | null => { const [value, setValue] = useState(props.value); useEffect(() => setValue(props.value), [props.value]) const onChange = (ev: any, value: string | undefined) => { let jsonObj = json.tryParse(value); let jsonStringValue = jsonObj ? json.tryStringify(jsonObj) : undefined; setValue(jsonStringValue); props.onChange(jsonStringValue); } return props.onBlur(props.value)} errorMessage={props.errorMessage ? `${props.errorMessage} and string must be of correct JSON format` : undefined } /> }