Cannot read property 'setAllowScrolling' of undefined. React with fullPage.js

I am trying to disable scrolling while a modal pop-up is open. The following if statement does disable scroll while the modal is open, but after the modal is closed, scrolling is still disabled

if (isMoreInfoOpen === true) {
    fullpageApi.setAllowScrolling(false);
} 

To fix that issue, I added an else statement to turn scrolling back on after the modal has been closed.

if (isMoreInfoOpen === true) {
    fullpageApi.setAllowScrolling(false);
} else {
   fullpageApi.setAllowScrolling(true);
}

However, adding the else statement causes an error:
Cannot read property ‘setAllowScrolling’ of undefined

I’ve recreated the issue here: https://7pq3i.csb.app/

69 thoughts on “Cannot read property 'setAllowScrolling' of undefined. React with fullPage.js”

Leave a Comment