Support basePath in all queries.

This commit is contained in:
Mike Cao 2020-09-30 22:34:16 -07:00
parent 2508198a51
commit 5068ab12a9
11 changed files with 57 additions and 29 deletions

View file

@ -2,6 +2,7 @@ import { useState, useEffect } from 'react';
import { useDispatch } from 'react-redux';
import { get } from 'lib/web';
import { updateQuery } from 'redux/actions/queries';
import { useRouter } from 'next/router';
export default function useFetch(url, params = {}, options = {}) {
const dispatch = useDispatch();
@ -9,6 +10,7 @@ export default function useFetch(url, params = {}, options = {}) {
const [status, setStatus] = useState();
const [error, setError] = useState();
const [loading, setLoadiing] = useState(false);
const { basePath } = useRouter();
const keys = Object.keys(params)
.sort()
.map(key => params[key]);
@ -19,7 +21,7 @@ export default function useFetch(url, params = {}, options = {}) {
setLoadiing(true);
setError(null);
const time = performance.now();
const { data, status } = await get(url, params);
const { data, status } = await get(`${basePath}${url}`, params);
dispatch(updateQuery({ url, time: performance.now() - time, completed: Date.now() }));