import { useCallback } from 'react'
import { useFetch } from '../../../../hooks/fetch'

/**
 * It takes a formId and a fetch function, and returns the data from the fetch function
 * @param formId - The id of the form to fetch.
 * @param fetch - A function that takes a formId and returns a promise.
 * @returns A function that returns the data from the form.
 */
const useGetForm = (formId, fetch) => {
  const formFetch = useCallback(() => formId && fetch?.(formId), [
    formId,
    fetch
  ])

  const data = useFetch(formFetch)

  return data
}

export default useGetForm
