Code-Society-Lab / cursif-web

React client for Cursif
2 stars 5 forks source link

Notiflix - Cannot read properties of undefined #26

Closed PenguinBoi12 closed 3 months ago

PenguinBoi12 commented 8 months ago

Investigate notiflix throwing a weird "cannot read properties of undefined" when page is loaded. (see image bellow) image

piro56 commented 7 months ago

https://github.com/notiflix/Notiflix/issues/75 Issue I am guessing is that the init() may be trying to reference a DOM element somehow, or needs to be somewhere within useEffect. Calling init() in a use effect causes it to work as expected.

Possible Solution

Refactor notiflix-config to now have a wrapped useEffect hook that initializes config on page load

function useNotify() {
    useEffect(() => {
        Notify.init({
        ...
        })
}
export {
    Notify, useNotify
}

Then to use:

import {Notify, useNotify} from '@config/notiflix-config';

export default function Page() {
  useNotify();
  // Use the same as before
  Notify.success("Loaded!"); 
}