0

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?

Alpaca
  • 148
  • 3
  • 8

1 Answers1

2

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