Getting form data in a React component
If you need to retrieve data from a form when the user fills it out, you can
get formData field from the FormViewer
ref, and also
use onFormDataChange callback in FormViewer
props.
export const Viewer = () => {
const ref = useRef<IFormViewer>()
const setRef = (viewer: IFormViewer | null) => {
if (viewer) {
ref.current = viewer
const formJSON = JSON.stringify(ref.current.formData)
console.log('formJSON ', ref.current)
}
}
return (
<FormViewer
onFormDataChange={({data, errors}) => {
const formJSON = JSON.stringify(data)
console.log('onFormDataChange', formJSON)
}}
viewerRef={setRef}
{...otherProps}
/>
)
}