request.js

import useSWR from 'swr';
import { config } from '../../utility/config/index';

const fetcher = (url) => window.fetch(url).then((res) => res.json());
const url = config.API_BACKEND;
const options = { revalidateOnFocus: false };

// path sample: /use/recommendations
function useCocoApi({ path }) {
  const { data, error } = useSWR(`${url}${path}`, fetcher, options);

  return [data, error];
}

export default useCocoApi;