mirror of
https://github.com/grafana/grafana.git
synced 2025-09-21 03:33:12 +08:00

* Change nav structure when topnav is enable to do initial tests with new information architecture * Support for nested sections * Updated * sentance case * Progress on plugin challange * Rewrite to functional component * Progress * Updates * Progress * Progress on things * missing file * Fixing issue with runtime, need to use setter way to set component exposed via runtime * Move PageLayoutType to grafana/data * Fixing breadcrumb issue, adding more tests * reverted backend change * fix recursive issue with cleanup
17 lines
603 B
TypeScript
17 lines
603 B
TypeScript
import { useEffect, useRef } from 'react';
|
|
import { useDispatch } from 'react-redux';
|
|
|
|
import { cleanUpAction, CleanUpAction } from '../actions/cleanUp';
|
|
|
|
export function useCleanup(cleanupAction: CleanUpAction) {
|
|
const dispatch = useDispatch();
|
|
//bit of a hack to unburden user from having to wrap stateSelcetor in a useCallback. Otherwise cleanup would happen on every render
|
|
const selectorRef = useRef(cleanupAction);
|
|
selectorRef.current = cleanupAction;
|
|
useEffect(() => {
|
|
return () => {
|
|
dispatch(cleanUpAction({ cleanupAction: selectorRef.current }));
|
|
};
|
|
}, [dispatch]);
|
|
}
|