I'm trying to build a React component where I need to calculate the time difference between onMouseEnter and onMouseLeave when I hover over a div? I have added "time" in the state but dunno how to continue it. Since I'm a beginner in React I'm not able to get it working. Please help....Also, when I try to display these elements, I'm not sure about the timeStamp property that gets displayed.
import React from 'react';
import '../Hover/Hover.css';
class Hover extends React.Component {
constructor(props) {
super(props);
this.handleMouseEnter = this.handleMouseEnter.bind(this);
this.handleMouseLeave = this.handleMouseLeave.bind(this);
this.state = {
isHovering: false,
time: 0
}
}
handleMouseEnter(elementEnter){
console.log("mouseenter : ", elementEnter.timeStamp)
this.setState({
isHovering: true
})
}
handleMouseLeave(elementLeave) {
console.log("mouseleave : ", elementLeave.timeStamp)
this.setState({
isHovering: false
})
}
render() {
return(
<div className="hover" onMouseEnter={this.handleMouseEnter} onMouseLeave={this.handleMouseLeave}>
<h1>Hover Component</h1>
</div>
)
}
}