Fix bug UI and update variable name

This commit is contained in:
2023-10-30 14:57:53 +07:00
parent 96bbe99523
commit af4af45aeb
3 changed files with 13 additions and 13 deletions
+5 -5
View File
@@ -3,7 +3,7 @@ import { useEffect, useState } from 'react';
// Constants
import { BASE_URL } from '../constants/path';
export const useFetch = (path: string, keyPhone: string, reload?: boolean) => {
export const useFetch = (path: string, phoneNum: string, reload?: boolean) => {
const [data, setData] = useState(null);
const [isPending, setIsPending] = useState(false);
const [errorMsg, setErrorMsg] = useState<string | null>(null);
@@ -16,12 +16,12 @@ export const useFetch = (path: string, keyPhone: string, reload?: boolean) => {
setIsPending(true);
// prettier-ignore
const phoneSearchQuery = keyPhone
? `?phone_like=${keyPhone}`
const query = phoneNum
? `?phone_like=${phoneNum}`
: '';
try {
const response = await fetch(BASE_URL + path + phoneSearchQuery);
const response = await fetch(BASE_URL + path + query);
const json = await response.json();
if (!response.ok)
@@ -39,6 +39,6 @@ export const useFetch = (path: string, keyPhone: string, reload?: boolean) => {
};
fetchData();
}, [path, reload, keyPhone]);
}, [path, reload, phoneNum]);
return { data, isPending, errorMsg };
};