fix: remove conditions for an infinite React hooks loop (#81)

The useAlert hook was being given a new payload object every time it was called, defeating any memoization happening inside.

It was also re-calling it’s useEffect hook when alertId changed, which it was changing itself. That’s a no-no.
This commit is contained in:
David Joy
2020-06-10 17:08:07 -04:00
committed by GitHub
parent a8d01c423d
commit 65173e9f93
2 changed files with 5 additions and 2 deletions

View File

@@ -1,4 +1,5 @@
/* eslint-disable import/prefer-default-export */
import { useMemo } from 'react';
import { useModel } from '../../model-store';
import { useAlert } from '../../user-messages';
@@ -7,9 +8,11 @@ export function useAccessExpirationAlert(courseId) {
const rawHtml = (course && course.courseExpiredMessage) || null;
const isVisible = !!rawHtml; // If it exists, show it.
const payload = useMemo(() => ({ rawHtml }), [rawHtml]);
useAlert(isVisible, {
code: 'clientAccessExpirationAlert',
topic: 'course',
payload: { rawHtml },
payload,
});
}

View File

@@ -22,5 +22,5 @@ export function useAlert(isVisible, {
remove(alertId);
}
};
}, [alertId, isVisible, code, text, topic, type, dismissible, payload]);
}, [isVisible, code, text, topic, type, dismissible, payload]);
}