27 lines
617 B
JavaScript
27 lines
617 B
JavaScript
import { useState, useEffect } from 'react';
|
|
import { getConfig } from '../services/config';
|
|
|
|
const useConfig = () => {
|
|
const [config, setConfig] = useState(null);
|
|
const [loading, setLoading] = useState(true);
|
|
const [error, setError] = useState(null);
|
|
|
|
useEffect(() => {
|
|
const fetchConfig = async () => {
|
|
try {
|
|
const response = await getConfig();
|
|
setConfig(response.data);
|
|
} catch (err) {
|
|
setError(err.message);
|
|
} finally {
|
|
setLoading(false);
|
|
}
|
|
};
|
|
|
|
fetchConfig();
|
|
}, []);
|
|
|
|
return { config, loading, error };
|
|
};
|
|
|
|
export default useConfig; |