@@ -60,11 +60,11 @@ class LazyLoadImage extends React.Component {
6060 }
6161
6262 componentDidUpdate ( ) {
63- if ( this . refs . placeholder ) {
63+ if ( this . placeholder ) {
6464 const boundingBox = {
65- bottom : this . refs . placeholder . offsetTop +
66- this . refs . placeholder . offsetHeight ,
67- top : this . refs . placeholder . offsetTop
65+ bottom : this . placeholder . offsetTop +
66+ this . placeholder . offsetHeight ,
67+ top : this . placeholder . offsetTop
6868 } ;
6969
7070 if ( this . previousBoundingBox . bottom !== boundingBox . bottom ||
@@ -91,18 +91,18 @@ class LazyLoadImage extends React.Component {
9191 }
9292
9393 isImageInViewport ( scrollPosition ) {
94- if ( ! this . refs . placeholder ) {
94+ if ( ! this . placeholder ) {
9595 return false ;
9696 }
9797
9898 const { threshold } = this . props ;
9999 const boundingBox = {
100- bottom : this . refs . placeholder . offsetTop +
101- this . refs . placeholder . offsetHeight ,
102- left : this . refs . placeholder . offsetLeft ,
103- right : this . refs . placeholder . offsetLeft +
104- this . refs . placeholder . offsetWidth ,
105- top : this . refs . placeholder . offsetTop
100+ bottom : this . placeholder . offsetTop +
101+ this . placeholder . offsetHeight ,
102+ left : this . placeholder . offsetLeft ,
103+ right : this . placeholder . offsetLeft +
104+ this . placeholder . offsetWidth ,
105+ top : this . placeholder . offsetTop
106106 } ;
107107 const viewport = {
108108 bottom : scrollPosition . y + window . innerHeight ,
@@ -123,12 +123,13 @@ class LazyLoadImage extends React.Component {
123123 const { className, height, placeholder, width } = this . props ;
124124
125125 if ( placeholder ) {
126- return React . cloneElement ( placeholder , { ref : 'placeholder' } ) ;
126+ return React . cloneElement ( placeholder ,
127+ { ref : el => this . placeholder = el } ) ;
127128 }
128129
129130 return (
130131 < span className = { 'lazy-load-image-placeholder ' + className }
131- ref = " placeholder"
132+ ref = { el => this . placeholder = el }
132133 style = { { height, width } } >
133134 </ span >
134135 ) ;
@@ -145,7 +146,7 @@ class LazyLoadImage extends React.Component {
145146 return (
146147 < img
147148 { ...props }
148- ref = " image" />
149+ ref = { img => this . image = img } />
149150 ) ;
150151 }
151152}
0 commit comments