grafana/public/app/features/alerting/unified/hooks/useManagedAlertStateHistory.ts
kay delaney 64bbb7a7ce
Chore: Update and enforce usage of typed react-redux hooks (#55349)
* Chore: Update and enforce usage of typed react-redux hooks
2022-09-19 10:49:35 +01:00

23 lines
692 B
TypeScript

import { useEffect } from 'react';
import { useDispatch } from 'app/types';
import { StateHistoryItem } from 'app/types/unified-alerting';
import { fetchGrafanaAnnotationsAction } from '../state/actions';
import { AsyncRequestState } from '../utils/redux';
import { useUnifiedAlertingSelector } from './useUnifiedAlertingSelector';
export function useManagedAlertStateHistory(alertId: string) {
const dispatch = useDispatch();
const history = useUnifiedAlertingSelector<AsyncRequestState<StateHistoryItem[]>>(
(state) => state.managedAlertStateHistory
);
useEffect(() => {
dispatch(fetchGrafanaAnnotationsAction(alertId));
}, [dispatch, alertId]);
return history;
}