@@ -14,11 +14,10 @@ class Image extends CloudinaryComponent {
1414 constructor ( props , context ) {
1515 super ( props , context ) ;
1616 this . handleResize = this . handleResize . bind ( this ) ;
17-
18- this . state = { } ;
17+ this . attachRef = this . attachRef . bind ( this ) ;
1918
2019 let state = { responsive : false , url : undefined , breakpoints : defaultBreakpoints } ;
21- this . state = Object . assign ( state , this . prepareState ( props , context ) ) ;
20+ this . state = { ... state , ... this . prepareState ( props , context ) } ;
2221 }
2322
2423 /**
@@ -60,6 +59,19 @@ class Image extends CloudinaryComponent {
6059 return state ;
6160 }
6261
62+ attachRef ( element ) {
63+ this . element = element ;
64+ const { innerRef} = this . props ;
65+
66+ if ( innerRef ) {
67+ if ( innerRef instanceof Function ) {
68+ innerRef ( element ) ;
69+ } else {
70+ innerRef . current = element ;
71+ }
72+ }
73+ }
74+
6375 handleResize ( ) {
6476 if ( ! this . props . responsive || this . rqf ) return ;
6577 this . rqf = requestAnimationFrame ( ( ) => {
@@ -98,14 +110,12 @@ class Image extends CloudinaryComponent {
98110 }
99111
100112 render ( ) {
101- const { publicId, responsive, responsiveDebounce, children, ...options } =
113+ const { publicId, responsive, responsiveDebounce, children, innerRef , ...options } =
102114 CloudinaryComponent . normalizeOptions ( this . props , this . getContext ( ) ) ;
103115 const attributes = cloudinary . Transformation . new ( options ) . toHtmlAttributes ( ) ;
104116 const { url} = this . state ;
105117 return (
106- < img { ...attributes } src = { url } ref = { ( e ) => {
107- this . element = e ;
108- } } />
118+ < img { ...attributes } src = { url } ref = { this . attachRef } />
109119 ) ;
110120 }
111121
0 commit comments