From c6184e5786bfee74786425ded33f02656083d153 Mon Sep 17 00:00:00 2001 From: Wroud Date: Tue, 31 Aug 2021 13:32:51 +0300 Subject: [PATCH] refactor(core-blocks): CB-1094 SubmittingForm component --- .../src/FormControls/SubmittingForm.tsx | 28 ++++++++++--------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/webapp/packages/core-blocks/src/FormControls/SubmittingForm.tsx b/webapp/packages/core-blocks/src/FormControls/SubmittingForm.tsx index 465df017a0..86b40b8d8b 100644 --- a/webapp/packages/core-blocks/src/FormControls/SubmittingForm.tsx +++ b/webapp/packages/core-blocks/src/FormControls/SubmittingForm.tsx @@ -6,7 +6,7 @@ * you may not use this file except in compliance with the License. */ -import { useCallback, forwardRef, useState, useContext } from 'react'; +import { forwardRef, useContext } from 'react'; import { Executor } from '@cloudbeaver/core-executor'; @@ -28,26 +28,28 @@ export const SubmittingForm = forwardRef(fun }, ref ) { - const parentContext = useContext(FormContext); - const props = useObjectRef({ parentContext, onChange, onSubmit }); - const [changeExecutor] = useState(() => new Executor()); - - const handleSubmit = useCallback((e: React.FormEvent) => { - e.preventDefault(); - props.onSubmit?.(e); - }, []); + const props = useObjectRef(() => ({ + handleSubmit(e: React.FormEvent) { + e.preventDefault(); + this.onSubmit?.(e); + }, + }), { + parentContext: useContext(FormContext), + onChange, + onSubmit, + }, ['handleSubmit']); const context = useObjectRef(() => ({ - changeExecutor, + changeExecutor: new Executor(), change(value, name) { props.onChange(value, name); props.parentContext?.change(value, name); - changeExecutor.execute({ value, name }); + this.changeExecutor.execute({ value, name }); }, - }), false); + }), false, ['change']); return ( -
+
{children}