mirror of
https://github.com/Nezumi-2711/react-training.git
synced 2026-09-22 13:38:51 +00:00
Implement add user function
This commit is contained in:
@@ -3,12 +3,15 @@ import { useEffect, useState } from 'react';
|
||||
// Constants
|
||||
import { BASE_URL } from '../constants/path';
|
||||
|
||||
export const useFetch = (path: string) => {
|
||||
export const useFetch = (path: string, reload?: boolean) => {
|
||||
const [data, setData] = useState(null);
|
||||
const [isPending, setIsPending] = useState(false);
|
||||
const [errorMsg, setErrorMsg] = useState<string | null>(null);
|
||||
|
||||
useEffect(() => {
|
||||
// Clear data
|
||||
setData(null);
|
||||
|
||||
const fetchData = async () => {
|
||||
setIsPending(true);
|
||||
|
||||
@@ -31,6 +34,6 @@ export const useFetch = (path: string) => {
|
||||
};
|
||||
|
||||
fetchData();
|
||||
}, [path]);
|
||||
}, [path, reload]);
|
||||
return { data, isPending, errorMsg };
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user