Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use ref in Mascot component rather than reaching into DOM directly #7893

Merged
merged 1 commit into from
Jan 24, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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'
Gudahtt marked this conversation as resolved.
Show resolved Hide resolved
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