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:
@@ -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,
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user