import React, { FC, useEffect, useState } from 'react' import { useFetchWithAuth } from '../../hooks/useFetchWithAuth'; import { Control, Controller, FieldValues, useFieldArray, useForm, UseFormRegister } from 'react-hook-form'; interface Props { attribute: string, keyRegiter?: any, control: Control, } export const Manytooneform: FC = ({ attribute, keyRegiter, control }) => { if (!keyRegiter){ keyRegiter=attribute; } const [data, setData] = useState([{id:0,nombre:'Select one', documentNumber: 0} ]); useEffect(() => { async function fetchData() { try { const { data, error } = await useFetchWithAuth(attribute.toLowerCase()); setData(data); } catch (error) { console.error(error); } } fetchData(); }, [attribute]); return (
( )} name={keyRegiter} control={control} />
) }