I am trying to use the register() method in my child component. But I am getting a Typescript Error saying: Expected 1-2 arguments, but got 0.
I am assuming I am passing the register method incorrectly?
Parent Component
type FormValues = {
projectType: string;
};
const Parent = () => {
const {
register,
} = useForm<FormValues>({ mode: 'all' });
return (
<Container>
<FormBlock id="form">
<fieldset>
<ChildComponent props={register()}/>
</fieldset>
</FormBlock>
</Container>
);
};
Child Component
const ChildComponent = ({ props }) => {
return (
<InputField {...props.register('projectType')}></InputField
);
};
this.register?registeryou are not passing the function toChildComponentbut the return value. Also you wouldn't pass a proppropsto a component. The arguments provided toChildComponentare already the props and wrapped into an object. Just passregister={register}.