Skip to content

Commit 2da3382

Browse files
author
Ruben van Leeuwen
committed
2076: Reset formInput and history if formKey changes
1 parent 008d6f6 commit 2da3382

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

frontend/packages/pydantic-forms/src/core/PydanticFormContextProvider.tsx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,17 @@ function PydanticFormContextProvider({
7979
);
8080
const [formInputData, setFormInputData] = useState<object[]>([]);
8181

82+
const formRef = useRef<string>(formKey);
83+
84+
useEffect(() => {
85+
if (formKey !== formRef.current) {
86+
// When the formKey changes we need to reset the form input data
87+
setFormInputData([]);
88+
setFormInputHistory(new Map<string, object>());
89+
formRef.current = formKey;
90+
}
91+
}, [formKey]);
92+
8293
const updateHistory = async (
8394
formInput: object,
8495
previousSteps: object[],

0 commit comments

Comments
 (0)