File tree Expand file tree Collapse file tree 2 files changed +9
-1
lines changed
Expand file tree Collapse file tree 2 files changed +9
-1
lines changed Original file line number Diff line number Diff line change @@ -41,6 +41,7 @@ import ImageOnLoad from 'react-image-onload';
4141
4242``` js
4343type Props = {
44+ src: string,
4445 onLoad : (image : HTMLImageElement ) => Promise < void > | void ,
4546};
4647```
Original file line number Diff line number Diff line change @@ -5,11 +5,13 @@ import omit from 'ramda/src/omit';
55import PropTypes from 'prop-types' ;
66
77export type Props = {
8+ src : string ,
89 onLoad : ( image : HTMLImageElement ) => Promise < void > | void ,
910} ;
1011
1112class InputOnLoad extends React . Component < Props > {
1213 static propTypes = {
14+ src : PropTypes . string ,
1315 onLoad : PropTypes . func . isRequired , // (image: HTMLImageElement) => Promise<void> | void,
1416 } ;
1517 componentDidMount ( ) {
@@ -21,6 +23,11 @@ class InputOnLoad extends React.Component<Props> {
2123 onLoad ( image ) ;
2224 }
2325 }
26+ componentWillReceiveProps ( nextProps : Props ) {
27+ if ( nextProps . src !== this . props . src ) {
28+ this . isLoaded = false ;
29+ }
30+ }
2431 componentWillUnmount ( ) {
2532 this . isLoaded = false ;
2633 }
@@ -37,7 +44,7 @@ class InputOnLoad extends React.Component<Props> {
3744 props: Props ;
3845 render ( ) {
3946 const { onRef, onLoad } = this ;
40- const otherProps = omit ( [ 'onLoad' ] ) ( this . props ) ;
47+ const otherProps : Object = omit ( [ 'onLoad' ] ) ( this . props ) ;
4148
4249 return < img ref = { onRef } onLoad = { onLoad } { ...otherProps } /> ;
4350 }
You can’t perform that action at this time.
0 commit comments