Created
November 30, 2019 19:09
-
-
Save 01Clarian/0f0c2b1ed1fbff9eb0ba893f94fb54a9 to your computer and use it in GitHub Desktop.
HoverCounter pre HOC pattern
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react'; | |
class HoverCounter extends React.Component { | |
constructor() { | |
super() | |
this.state = { | |
count: 0 | |
} | |
} | |
increment = () => { | |
this.setState(prevState => { | |
return {count: prevState.count + 1} | |
}) | |
} | |
render(){ | |
const {count} = this.state | |
return ( | |
<h2 onMouseOver={this.increment}> | |
{count}</h2> | |
); | |
}} | |
export default HoverCounter; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment