1
0
mirror of https://gitlab.nic.cz/turris/reforis/foris-js.git synced 2024-12-26 00:21:36 +01:00

Merge branch 'api-polling-catch-error' into 'dev'

Catch error state in API polling.

See merge request turris/reforis/foris-js!44
This commit is contained in:
Bogdan Bodnar 2019-11-19 16:56:38 +00:00
commit 1dcba1dfa8

View File

@ -95,13 +95,13 @@ export {
export function useAPIPolling(endpoint, delay = 1000, until) { // delay ms export function useAPIPolling(endpoint, delay = 1000, until) { // delay ms
const [state, setState] = useState({ state: API_STATE.INIT }); const [state, setState] = useState({ state: API_STATE.INIT });
const [getState, get] = useAPIGet(endpoint); const [getResponse, get] = useAPIGet(endpoint);
useEffect(() => { useEffect(() => {
if (getState.state === API_STATE.SUCCESS) { if (getResponse.state !== API_STATE.INIT) {
setState(getState); setState(getResponse);
} }
}, [getState]); }, [getResponse]);
useEffect(() => { useEffect(() => {
if (until) { if (until) {