@@ -15,20 +15,21 @@ export default class ScrollToBottomComposer extends React.Component {
1515 this . state = {
1616 bottom : true ,
1717 handleUpdate : ( ) => this . state . bottom && this . state . scrollToBottom ( ) ,
18- scrollToBottom : ( ) => this . setState ( ( ) => ( {
19- scrollTop : this . state . target && this . state . target . current && ( this . state . target . current . scrollHeight - this . state . target . current . offsetHeight )
18+ scrollToBottom : ( ) => this . setState ( state => ( {
19+ scrollTop : state . target && state . target && ( state . target . scrollHeight - state . target . offsetHeight )
2020 } ) ) ,
2121 scrollTop : null ,
22- target : React . createRef ( )
22+ setTarget : target => this . setState ( ( ) => ( { target } ) ) ,
23+ target : null ,
2324 } ;
2425 }
2526
2627 handleScroll ( ) {
2728 this . setState ( ( ) => {
28- const { current } = this . state . target ;
29+ const { target } = this . state ;
2930
30- if ( current ) {
31- const { offsetHeight, scrollHeight, scrollTop } = current ;
31+ if ( target ) {
32+ const { offsetHeight, scrollHeight, scrollTop } = target ;
3233 const bottom = scrollHeight - scrollTop - offsetHeight <= this . props . threshold ;
3334
3435 return { bottom } ;
@@ -41,21 +42,26 @@ export default class ScrollToBottomComposer extends React.Component {
4142 }
4243
4344 render ( ) {
45+ const { scrollTop, target } = this . state ;
46+
4447 return (
4548 < Context . Provider value = { this . state } >
4649 { this . props . children }
47- < EventSpy
48- name = "scroll"
49- onEvent = { this . handleScroll }
50- target = { this . state . target . current }
51- />
5250 {
53- typeof this . state . scrollTop === 'number' &&
51+ target &&
52+ < EventSpy
53+ name = "scroll"
54+ onEvent = { this . handleScroll }
55+ target = { target }
56+ />
57+ }
58+ {
59+ target && typeof scrollTop === 'number' &&
5460 < SpineTo
5561 name = "scrollTop"
5662 onEnd = { this . handleScrollEnd }
57- target = { this . state . target . current }
58- value = { this . state . scrollTop }
63+ target = { target }
64+ value = { scrollTop }
5965 />
6066 }
6167 </ Context . Provider >
0 commit comments