{"size": 507, "ext": "js", "max_stars_repo_path": "part7/ultimate-hooks/src/hooks/useResource.js", "max_stars_repo_name": "izanlseco/full-stack-open-2021", "max_stars_repo_stars_event_min_datetime": "2022-02-03T11:55:52.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-17T11:36:18.000Z", "max_issues_repo_path": "part7/ultimate-hooks/src/hooks/useResource.js", "max_issues_repo_name": "izanlseco/full-stack-open-2021", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "part7/ultimate-hooks/src/hooks/useResource.js", "max_forks_repo_name": "izanlseco/full-stack-open-2021", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 2, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 18.7777777778, "max_line_length": 56, "alphanum_fraction": 0.6568047337}
import { useState } from 'react'
import axios from 'axios'

const useResource = (baseUrl) => {
  const [resources, setResources] = useState([])

  const getAll = async () => {
    const response = await axios.get(baseUrl)
    return setResources(response.data)
  }

  const create = async (resource) => {
    const response = await axios.post(baseUrl, resource)
    return response.data
  }

  const service = {
    create,
    getAll
  }

  return [
    resources, service
  ]
}

export default useResource