Skip to content

Instantly share code, notes, and snippets.

@cvan
Created May 26, 2020 03:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cvan/32d6b211fd0041ca40b0e673043e2a8b to your computer and use it in GitHub Desktop.
Save cvan/32d6b211fd0041ca40b0e673043e2a8b to your computer and use it in GitHub Desktop.
using `body-scroll-lock` npm package to prevent body scroll on iOS
import React, { useEffect } from 'react';
import * as bodyScrollLock from 'body-scroll-lock';
const disableBodyScroll = bodyScrollLock.disableBodyScroll;
const enableBodyScroll = bodyScrollLock.enableBodyScroll;
export default function Page() {
const appRef = React.createRef();
useEffect(() => {
if (scrollableContainerRef && scrollableContainerRef.current) {
disableBodyScroll(scrollableContainerRef.current);
}
return () => {
if (scrollableContainerRef && scrollableContainerRef.current) {
enableBodyScroll(scrollableContainerRef.current);
}
};
}, []);
return (
<div ref={scrollableContainerRef} />
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment