fix: useExamAccess hook does not make call to fetchExamAccessToken after isExam changes (#1644)
This commit fixes a bug that prevents the fetchExamAccessToken hook in the useExamAccess hook from running. This occurs when the value of isExam returned by the useIsExam hook changes from false to true. Because the dependency array of the useEffect hook within the useExamAccess hook was ['id'], the useEffect hook would not rerun on changes to isExam. The fix is to add isExam to the dependency array.
This commit is contained in:
@@ -18,9 +18,10 @@ const useExamAccess = ({
|
||||
const fetchExamAccessToken = useFetchExamAccessToken();
|
||||
|
||||
// NOTE: We cannot use this hook in the useEffect hook below to grab the updated exam access token in the finally
|
||||
// block, due to the rules of hooks. Instead, we get the value of the exam access token from a call to the hook.
|
||||
// block, due to the rules of hooks. Instead, we get the value of the exam access token from a call to
|
||||
// the hook below.
|
||||
// When the fetchExamAccessToken call completes, the useExamAccess hook will re-run
|
||||
// (due to a change to the Redux store, and, thus, a change to the the context), at which point the updated
|
||||
// (due to a change to the Redux store, and, thus, a change to the context), at which point the updated
|
||||
// exam access token will be fetched via the useExamAccessToken hook call below.
|
||||
// The important detail is that there should never be a return value (false, '').
|
||||
const examAccessToken = useExamAccessToken();
|
||||
@@ -35,7 +36,7 @@ const useExamAccess = ({
|
||||
logError(error);
|
||||
});
|
||||
}
|
||||
}, [id]);
|
||||
}, [id, isExam]);
|
||||
|
||||
return {
|
||||
blockAccess,
|
||||
|
||||
Reference in New Issue
Block a user