Skip to content

Commit

Permalink
Use ref in Mascot component rather than reaching into DOM directly (#…
Browse files Browse the repository at this point in the history
…7893)

Accessing the dom via `document` is strongly discouraged in React.
Instead the DOM element is now referenced by ref instead.
  • Loading branch information
Gudahtt authored Jan 24, 2020
1 parent 550fba2 commit 70a6894
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions ui/app/components/ui/mascot.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import PropTypes from 'prop-types'
import React, { Component } from 'react'
import React, { createRef, Component } from 'react'
import metamaskLogo from 'metamask-logo'
import debounce from 'debounce'

Expand All @@ -22,6 +22,8 @@ export default class Mascot extends Component {
height,
})

this.mascotContainer = createRef()

this.refollowMouse = debounce(this.logo.setFollowMouse.bind(this.logo, true), 1000)
this.unfollowMouse = this.logo.setFollowMouse.bind(this.logo, false)
}
Expand All @@ -43,9 +45,7 @@ export default class Mascot extends Component {
}

componentDidMount () {
const targetDivId = 'metamask-mascot-container'
const container = document.getElementById(targetDivId)
container.appendChild(this.logo.container)
this.mascotContainer.current.appendChild(this.logo.container)
}

componentWillUnmount () {
Expand All @@ -62,7 +62,7 @@ export default class Mascot extends Component {
this.handleAnimationEvents()
return (
<div
id="metamask-mascot-container"
ref={this.mascotContainer}
style={{ zIndex: 0 }}
/>
)
Expand Down

0 comments on commit 70a6894

Please sign in to comment.