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 questions for.
 * @param fetch - A function that takes a formId and returns a promise.
 * @returns A question object.
 */
const useGetQuestions = (formId, fetch) => {
  const questionsFetch = useCallback(() => formId && fetch?.(formId), [
    formId,
    fetch
  ])

  const data = useFetch(questionsFetch)

  return data
}

export default useGetQuestions
