CEC-5150: search on fleets in bulk action (#454)
* CEC-5150: search on fleets in bulk action * add deps * add deps * sonar * sonar * break out fetch
This commit is contained in:
@@ -1 +1,2 @@
|
||||
export { useTimeoutState } from "./useTimeoutState";
|
||||
export { useUpdateManifest } from "./useUpdateManifest";
|
||||
|
||||
21
src/hooks/useTimeoutState.js
Normal file
21
src/hooks/useTimeoutState.js
Normal file
@@ -0,0 +1,21 @@
|
||||
import { useCallback, useState } from "react";
|
||||
|
||||
export const useTimeoutState = (defaultState) => {
|
||||
const [state, _setState] = useState(defaultState);
|
||||
const [currentTimeoutId, setCurrentTimeoutId] = useState();
|
||||
|
||||
const setState = useCallback(
|
||||
(action, opts) => {
|
||||
if (currentTimeoutId != null) {
|
||||
clearTimeout(currentTimeoutId);
|
||||
}
|
||||
|
||||
_setState(action);
|
||||
|
||||
const id = setTimeout(() => _setState(defaultState), opts?.timeout);
|
||||
setCurrentTimeoutId(id);
|
||||
},
|
||||
[currentTimeoutId, defaultState]
|
||||
);
|
||||
return [state, setState];
|
||||
};
|
||||
Reference in New Issue
Block a user