compulim / react-scroll-to-bottom

React container that will auto scroll to bottom
MIT License
183 stars 35 forks source link

How to use scrollToBottom() ? #19

Open Steffi3rd opened 5 years ago

Steffi3rd commented 5 years ago

I would like to scroll at the bottom when I click on Submit Button.

It seems you have a function scrollToBottom() which do that job but I don't know how.

import ScrollToBottom from 'react-scroll-to-bottom';
<CommentZone>
       <ScrollToBottom animating={false} checkInterval={17}>
            <Comments>
               Comments<br />
               Comments<br />
               BOTTOM BABY<br />
             </Comments>
        </ScrollToBottom>
       <WriteComment>
             <Textarea maxRows={10} autoFocus />
             <Button onClick={() => scrollToBottom()}>Envoyer</Button>
        </WriteComment>
</CommentZone>
ashiquemohammed commented 5 years ago

Require the same .!!

Asinox commented 5 years ago

Just try this one with browser scrollIntoView():

<div refs="scroll"></div>

scroll(){
      const element = this.refs.scroll;
      element.scrollIntoView(false,{behavior: "smooth",block: "end"});
 }

componentDidUpdate(){
      this.scroll();
}

link: https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollIntoView

brspurri commented 5 years ago

I'm looking for a similar answer. I'd like to use FunctionContext methods, but can't find any explanation or example of how to do this.