ganderzz/react-scroll-to

Calling multiple functions when scrolling

Closed this issue · 1 comments

Please see this CodeSandbox example where I'm trying to console.log something when I scroll on the page. You can imagine use cases where a user might want to do other things, such as call Redux actions, click tracking, etc.

Because the handleScroll function returns a function (see here), I have to invoke the function like so:

console.log("You scrolled!");
scroll(0, 500)();

Do you think it'd be a cleaner API if the handleScroll function didn't return a function, but rather invoked it? This way, the user could just do:

console.log("You scrolled!");
scroll(0, 500);

This seems more intuitive to me, but would be a breaking change.

@newyork-anthonyng Sure. My use-case for this component mirrors the examples <Com onClick={scroll(0, 0)}, but I can see how it'd be more user friendly to not have to invoke the function twice.

I'll push the change out, and we'll mark the next release as being breaking.