question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

react custom scrollbar with react-window

See original GitHub issue

I am using react-custom-scrollbar and would like to integrate it with FixedSizeList.

I have checked the solution on this issue on react-virtualized: https://github.com/bvaughn/react-virtualized/issues/692#issuecomment-339393521

But the code is throwing error: Uncaught TypeError: Cannot read property 'handleScrollEvent' of undefined on scroll, in this function:

  handleScroll = ({ target }) => {
    const { scrollTop, scrollLeft } = target;

    const { Grid: grid } = this.List;

    grid.handleScrollEvent({ scrollTop, scrollLeft });
  }

I have added ref={ instance => { this.List = instance; } } on fixedSixe<List component.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:37 (3 by maintainers)

github_iconTop GitHub Comments

31reactions
piecykcommented, Mar 3, 2019

Better approach would be to pass Scrollbars as outerElementType

const CustomScrollbars = ({ onScroll, forwardedRef, style, children }) => {
  const refSetter = useCallback(scrollbarsRef => {
    if (scrollbarsRef) {
      forwardedRef(scrollbarsRef.view);
    } else {
      forwardedRef(null);
    }
  }, []);

  return (
    <Scrollbars
      ref={refSetter}
      style={{ ...style, overflow: "hidden" }}
      onScroll={onScroll}
    >
      {children}
    </Scrollbars>
  );
};

const CustomScrollbarsVirtualList = React.forwardRef((props, ref) => (
  <CustomScrollbars {...props} forwardedRef={ref} />
));

// ...

<FixedSizeList
  outerElementType={CustomScrollbarsVirtualList}
  {...rest}
/>

example https://codesandbox.io/s/vmr1l0p463

7reactions
bvaughncommented, Mar 3, 2019

I love how many advanced things are possible using outerElementType or innerElementType

Read more comments on GitHub >

github_iconTop Results From Across the Web

react-window with react-custom-scrollbar - CodeSandbox
CodeSandbox is an online editor tailored for web applications.
Read more >
How to make react-window FixedSizeList scroll with the ...
One solution is to use a package linked from the react-window github page called react-virtualized-auto-sizer. It is also made by bvaughn ...
Read more >
Creating Custom Scrollbars with React - This Dot Labs
This blog post shows you how to do just that using React and TypeScript. If you want to skip straight to the final...
Read more >
react-custom-scrollbars-2 - npm
React scrollbars component. Latest version: 4.5.0, last published: 6 months ago. Start using react-custom-scrollbars-2 in your project by ...
Read more >
Build an On-hover Custom Scrollbar in React - Level Up Coding
We all know the scroll bar is a UI component which commonly located on the far right or bottom of a window that...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found