refactor(steps): simplify step presenters by removing unnecessary useImperativeHandle calls

- Removed useImperativeHandle and getValues from BenefitsStep, ChallengesStep, ChartStep, ContactsStep, FeaturesStep, FooterStep, and HeroStep components.
- Updated step presenters to directly use refs for improved data handling and validation.
- Enhanced code readability and maintainability by streamlining the presenter functions.
This commit is contained in:
AmirReza Jamali
2026-04-18 12:41:48 +03:30
parent c1b6b4ccf1
commit 69e75eb9b8
16 changed files with 364 additions and 272 deletions
@@ -1,4 +1,5 @@
"use client";
import { ForwardedRef, useImperativeHandle } from "react";
import { useForm } from "react-hook-form";
export interface IHeroStepFields {
@@ -9,12 +10,16 @@ export interface IHeroStepFields {
gif_file: string;
}
const useHeroStepPresenter = (initialData?: IHeroStepFields) => {
const useHeroStepPresenter = (
initialData?: IHeroStepFields,
ref?: ForwardedRef<unknown>,
) => {
const {
register,
handleSubmit,
formState: { errors },
getValues,
trigger,
} = useForm<IHeroStepFields>({
defaultValues: initialData,
});
@@ -23,12 +28,16 @@ const useHeroStepPresenter = (initialData?: IHeroStepFields) => {
console.log(data);
};
useImperativeHandle(ref, () => ({
getData: () => getValues(),
validate: () => trigger(),
}));
return {
register,
handleSubmit,
errors,
onSubmit,
getValues,
};
};