r/reactjs • u/justicehwan • 3d ago
Show /r/reactjs Made my first npm library β <MrScroll /> stops scrollbars from shoving your layout around. Be honest with me π
Hey folks,
You know when a scrollbar pops in and everything jumps a few pixels to the left? That annoyed me enough that I made a little library for it.
**See it in 10 seconds (live demo):** https://justicehwan.github.io/plz-mr-scroll/
One line at the root of your app, that's it:
```tsx
import { MrScroll } from "plz-mr-scroll/react";
<MrScroll />
```
No reserved gutter, still the native scrollbar. It just finds a spot for the scrollbar so your content stays put. It never touches your children, so it doesn't fight React over the DOM.
- GitHub (GIFs in the README): https://github.com/justicehwan/plz-mr-scroll
- npm: https://www.npmjs.com/package/plz-mr-scroll
It's my first library ever, so I honestly have no idea what I got wrong. If you have a minute, please take a look and tell me what's broken or dumb π₯²
(Also haven't tried it on a real Windows machine yet β if you do, I'd love to know how it goes.)
P.S. I'm Korean and English isn't my first language, so sorry if anything here reads a bit off.
Thanks!
2
u/Honey-Entire 2d ago
Why is this a react component instead of a JS script you load from a CDN? I'd also recommend learning how to organize your code better because this is some of the most convoluted, difficult to read or maintain JS code I've ever seen. Very clearly AI-generated which leads me to believe you had a weird problem caused by poor design decisions rather than understanding how the browser renders content...
1
u/minimuscleR 2d ago
Why would you need this when you can just apply
scrollbar-gutter: stable;to the same effect.1
u/ybadev 2d ago
One Windows test Iβd put in the README: open and close a modal halfway down a long page with scrollbars set to always show. Check whether the header shifts and whether you end up at the same scroll position.