-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathImageCard.js
More file actions
39 lines (27 loc) · 834 Bytes
/
Copy pathImageCard.js
File metadata and controls
39 lines (27 loc) · 834 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import React from "react";
class ImageCard extends React.Component{
constructor(props) {
super(props);
this.state ={spans :0}
this.imageRef =React.createRef()
}
componentDidMount() {
this.imageRef.current.addEventListener("load",this.setSpans)
}
setSpans =()=>{
const height =(this.imageRef.current.clientHeight)
const spans =Math.ceil(height/10)
this.setState({spans})
}
render() {
const { description,urls} = this.props.image
return(
<div style={{gridRowEnd:`span ${this.state.spans}`}}>
<img alt ={description}
src={urls.regular}
ref={this.imageRef}/>
</div>
)
}
}
export default ImageCard