Skip to content

Commit

Permalink
fix: fix issue #19
Browse files Browse the repository at this point in the history
Read props at render time, instead of in the constructor. That way if
props change we're always reading the latest values.
  • Loading branch information
MatrixFrog committed Oct 7, 2021
1 parent b867091 commit 463b134
Showing 1 changed file with 17 additions and 26 deletions.
43 changes: 17 additions & 26 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,28 +13,6 @@ class Zoom extends Component {
mouseY: null,
}

const {
height,
img,
transitionTime,
width,
} = props

this.outerDivStyle = {
height: `${height}px`,
width: `${width}px`,
overflow: 'hidden',
}

this.innerDivStyle = {
height: `${height}px`,
backgroundRepeat: 'no-repeat',
backgroundPosition: 'center',
backgroundSize: 'auto 100%',
transition: `transform ${transitionTime}s ease-out`,
backgroundImage: `url('${img}')`,
}

this.imageRef = createRef()

this.handleMouseOver = this.handleMouseOver.bind(this)
Expand Down Expand Up @@ -85,17 +63,30 @@ class Zoom extends Component {
zoom,
} = this.state

const {
zoomScale,
} = this.props
const { zoomScale, height, width, img, transitionTime } = this.props

const transform = {
transformOrigin: `${mouseX}% ${mouseY}%`,
}

const outerDivStyle = {
height: `${height}px`,
width: `${width}px`,
overflow: "hidden",
};

const innerDivStyle = {
height: `${height}px`,
backgroundRepeat: "no-repeat",
backgroundPosition: "center",
backgroundSize: "auto 100%",
transition: `transform ${transitionTime}s ease-out`,
backgroundImage: `url('${img}')`,
};

return (
<div
style={this.outerDivStyle}
style={outerDivStyle}
onMouseOver={this.handleMouseOver}
onMouseOut={this.handleMouseOut}
onMouseMove={this.handleMouseMovement}
Expand Down

0 comments on commit 463b134

Please sign in to comment.