react-scroll-to-bottom icon indicating copy to clipboard operation
react-scroll-to-bottom copied to clipboard

Observer is not a function

Open astritspancasd opened this issue 5 years ago • 3 comments

When i try to use useObserveScrollPosition hook i got the error messsage: Observer is not a function

I copied one example in the docs and the issue is still there.

astritspancasd avatar Nov 17 '20 10:11 astritspancasd

To use useObserveScrollPosition hook:

// This is the content rendered inside the scrollable container
const ScrollContent = () => {
  const observer = useCallback(({ scrollTop }) => {
    console.log(scrollTop);
  }, []);

  useObserveScrollPosition(observer);

  return <div>Hello, World!</div>;
};

If you want to turn off the hook, in the render call, pass a falsy value, e.g. useObserveScrollPosition(false).

Please note that the observer will called very frequently, it is recommended:

  • Only observe the scroll position when needed
  • Don't put too much logic inside the callback function
  • If logic is needed, consider deferring handling using setTimeout or similar functions
  • Make sure the callback function passed on each render call is memoized appropriately, e.g. useCallback

compulim avatar Jan 04 '21 01:01 compulim

I receive the same error again and again. Can you give me an example of this?

astritspancasd avatar Jan 29 '21 10:01 astritspancasd

I receive the same error again and again. Can you give me an example of this?

astritspancasd avatar Jan 29 '21 10:01 astritspancasd