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

Scroll from child component

Open vebits opened this issue 8 years ago • 4 comments

Hi,

I have a parent and a child component. I want to have a button in the child component which onclick calls a function in the parent component. Inside this function I have the scrollToComponent method.

Inside the render method in the parent class I have this

<Home scroll={this.scrollToBooking} />

and in my child I have this

<button className="book-button" onClick={() => props.scroll()}>ORDER NOW</button>

The scroll() method does get executed but the scrolling is not working, anybody know why or is it another way to do this?

scrollToBooking looks like this:

scrollToBooking() { scrollToComponent(this.Booking, { offset: 0, align: 'top', duration: 1000}); }

vebits avatar Dec 05 '17 12:12 vebits

I am also trying to trigger the scrolling from a child component, any chance you figured something out?

JourdanLieblich avatar Feb 20 '18 03:02 JourdanLieblich

Got it working by passing a function from the parent component to the child for the button and calling scrollToX() from there. Works but is a bit choppy though that may be something on my end.

JourdanLieblich avatar Feb 20 '18 03:02 JourdanLieblich

+1

Way-U-Need avatar May 12 '20 09:05 Way-U-Need

@vebits @JourdanLieblich Did you find any solution to this? I am also stuck at same thing. I am able to execute the function but scrolling is not working.

architsingal avatar Apr 16 '21 09:04 architsingal