@formio/react
Advanced tools
Comparing version
@@ -154,5 +154,2 @@ "use strict"; | ||
} | ||
if (typeof formSource !== 'string') { | ||
formSource = (0, structured_clone_1.default)(formSource); | ||
} | ||
const promise = FormConstructor | ||
@@ -174,2 +171,3 @@ ? new FormConstructor(element, formSource, options) | ||
const renderElement = (0, react_1.useRef)(null); | ||
const currentFormJson = (0, react_1.useRef)(null); | ||
const { formConstructor, formSource, formReadyCallback } = getEffectiveProps(props); | ||
@@ -186,2 +184,7 @@ const { src, form, submission, url, options, formioform, formReady, FormClass, style, className } = props, handlers = __rest(props, ["src", "form", "submission", "url", "options", "formioform", "formReady", "FormClass", "style", "className"]); | ||
(0, react_1.useEffect)(() => { | ||
if (typeof formSource === 'object' && | ||
currentFormJson.current && | ||
js_1.Utils._.isEqual(currentFormJson.current, formSource)) { | ||
return; | ||
} | ||
const createInstance = () => __awaiter(void 0, void 0, void 0, function* () { | ||
@@ -196,3 +199,7 @@ if (renderElement.current === null) { | ||
} | ||
const instance = yield createWebformInstance(formConstructor, formSource, renderElement.current, options); | ||
currentFormJson.current = | ||
formSource && typeof formSource !== 'string' | ||
? (0, structured_clone_1.default)(formSource) | ||
: null; | ||
const instance = yield createWebformInstance(formConstructor, currentFormJson.current || formSource, renderElement.current, options); | ||
if (instance) { | ||
@@ -227,8 +234,10 @@ if (typeof formSource === 'string') { | ||
(0, react_1.useEffect)(() => { | ||
let onAnyHandler = null; | ||
if (formInstance && Object.keys(handlers).length > 0) { | ||
formInstance.onAny((...args) => onAnyEvent(handlers, ...args)); | ||
onAnyHandler = (...args) => onAnyEvent(handlers, ...args); | ||
formInstance.onAny(onAnyHandler); | ||
} | ||
return () => { | ||
if (formInstance && Object.keys(handlers).length > 0) { | ||
formInstance.offAny((...args) => onAnyEvent(handlers, ...args)); | ||
if (formInstance && onAnyHandler) { | ||
formInstance.offAny(onAnyHandler); | ||
} | ||
@@ -235,0 +244,0 @@ }; |
{ | ||
"name": "@formio/react", | ||
"version": "6.0.0-dev.597.5daa202", | ||
"version": "6.0.0-dev.598.928e477", | ||
"description": "React renderer for form.io forms.", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
Sorry, the diff of this file is not supported yet
242979
0.15%3805
0.24%