ConceptPortal-public/rsconcept/frontend/src/hooks/useRSForms.ts

25 lines
719 B
TypeScript
Raw Normal View History

import { useCallback, useEffect, useState } from 'react'
2023-07-15 17:46:19 +03:00
import { IRSForm } from '../models'
import { ErrorInfo } from '../components/BackendError';
import { getRSForms } from '../backendAPI';
2023-07-15 17:46:19 +03:00
export function useRSForms() {
const [rsforms, setRSForms] = useState<IRSForm[]>([]);
const [loading, setLoading] = useState(false);
const [error, setError] = useState<ErrorInfo>(undefined);
const fetchData = useCallback(async () => {
getRSForms({
showError: true,
setLoading: setLoading,
onError: error => setError(error),
onSucccess: response => setRSForms(response.data)
2023-07-15 17:46:19 +03:00
});
}, []);
2023-07-15 17:46:19 +03:00
useEffect(() => {
fetchData();
}, [fetchData])
2023-07-15 17:46:19 +03:00
return { rsforms, error, loading };
}