{"size": 567, "ext": "js", "max_stars_repo_path": "src/hooks/useReadFileContent.js", "max_stars_repo_name": "LuanEdCosta/carrijeta-sql-formatter", "max_stars_repo_stars_event_min_datetime": "2020-03-30T11:17:52.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-06T13:04:19.000Z", "max_issues_repo_path": "src/hooks/useReadFileContent.js", "max_issues_repo_name": "LuanEdCosta/carrijeta-sql-formatter", "max_issues_repo_issues_event_min_datetime": "2022-02-13T09:27:12.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-27T02:05:10.000Z", "max_forks_repo_path": "src/hooks/useReadFileContent.js", "max_forks_repo_name": "LuanEdCosta/carrijeta-sql-formatter", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 3, "max_issues_count": 2, "max_forks_count": null, "avg_line_length": 22.68, "max_line_length": 52, "alphanum_fraction": 0.6119929453}
/* eslint-disable no-alert */

import { useCallback } from 'react'
import { useTranslation } from 'react-i18next'

export default (onLoadFile) => {
  const { t } = useTranslation('Error')

  const onReadFileContent = useCallback(
    (e) => {
      if (typeof window.FileReader === 'function') {
        const [file] = e.target.files
        const fileReader = new FileReader()
        fileReader.onload = onLoadFile
        fileReader.readAsText(file)
      } else {
        alert(t('readFile'))
      }
    },
    [onLoadFile, t],
  )

  return onReadFileContent
}
