Skip to content

Commit

Permalink
Remove resize event listener when the component is unmounted.
Browse files Browse the repository at this point in the history
  • Loading branch information
sarukuku committed Dec 22, 2016
1 parent b2c24fa commit 089eb8a
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
2 changes: 1 addition & 1 deletion lib/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-flowtype",
"version": "1.0.4",
"version": "1.0.5",
"description": "React implementation of flowtype.js: font-size based on element width. Allows you to keep the ideal amount of characters per line, while scaling font size.",
"main": "lib/index.js",
"scripts": {
Expand Down
13 changes: 10 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,19 @@ import React, {PropTypes} from 'react'

export default class FlowType extends React.Component {

constructor () {
super()
this.updateWidthFont = this.updateWidthFont.bind(this)
}

componentDidMount () {
this.updateSettings()
this.updateWidthFont()
if (typeof window !== 'undefined') {
window.addEventListener('resize', this.updateWidthFont.bind(this))
}
window.addEventListener('resize', this.updateWidthFont)
}

componentWillUnmount () {
window.removeEventListener('resize', this.updateWidthFont)
}

componentWillReceiveProps () {
Expand Down

0 comments on commit 089eb8a

Please sign in to comment.