You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It's very challenging to avoid layout shift when you remove the scrollbar from the window. Many UI libraries still face issues with this, experiencing layout shifts when they open a modal or freeze scroll in some way. After testing numerous approaches I found an approach that avoids layout shifts while removing the scrollbar and freezing the scroll.
The useFreezeScroll hook freezes the scroll and removes the scrollbar from the browser window when it is active, without causing any layout shifts. This is particularly useful, for example, when a modal is opened.
import{useFreezeScroll}from'ahooks';importReact,{useState}from'react';exportdefault()=>{const[isActive,setIsActive]=useState(false);useFreezeScroll(isActive);return(<divstyle={{height: '300px'}}><divstyle={{height: '5000px'}}><divstyle={{marginTop: '20px'}}><p>Scroll should be frozen when enabled.</p><p>Try scrolling to test the effect.</p></div><buttononClick={()=>setIsActive(!isActive)}style={{position: 'sticky',top: '100px'}}>{isActive ? 'Disable Freeze Scroll' : 'Enable Freeze Scroll'}</button></div></div>);};
The text was updated successfully, but these errors were encountered:
It's very challenging to avoid layout shift when you remove the scrollbar from the window. Many UI libraries still face issues with this, experiencing layout shifts when they open a modal or freeze scroll in some way. After testing numerous approaches I found an approach that avoids layout shifts while removing the scrollbar and freezing the scroll.
The useFreezeScroll hook freezes the scroll and removes the scrollbar from the browser window when it is active, without causing any layout shifts. This is particularly useful, for example, when a modal is opened.
The text was updated successfully, but these errors were encountered: