Reputation: 166
I want to display scrollbar when the user first accesses each page
So I tried the code below:
function App() {
const app = document.querySelector("#root");
const [scrollHeight, setScrollHeight] = useState(app?.scrollHeight);
useEffect(() => {
setScrollHeight(app.scrollHeight);
}, [scrollHeight])
if (scrollHeight > window.innerHeight) {
/* show scrollbar and do something */
}
return (/* some components */);
}
Isn't there a better idea?
Upvotes: 0
Views: 44
Reputation: 21
In page.css or wrapper html element of Page component, you can set.
For page.css:
{ overflow: auto }
For wrapper html element:
"<div style={{overflow: 'auto'}}>"
Document link: overflow css
Upvotes: 2