Created
August 3, 2017 23:16
-
-
Save dan-tenovski/94ec25941a89cad8d6628c26d0ad2f43 to your computer and use it in GitHub Desktop.
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, { Component } from 'react'; | |
let HOCGen = (Component)=>class extends React.Component{ | |
constructor(props){ | |
super(props); | |
this.state = { | |
count: 0 | |
} | |
} | |
componentDidMount(){ | |
setInterval(()=>{ | |
this.setState({ | |
count: this.state.count + 1 | |
}) | |
}, 500) | |
} | |
render(){ | |
return ( | |
<Component {...this.props} {...this.state}/> | |
) | |
} | |
} | |
class Comp1 extends React.Component{ | |
render(){ | |
return ( | |
<div> | |
<p>Comp1</p> | |
{this.props.count} | |
</div> | |
) | |
} | |
} | |
let WrappedComp1 = HOCGen(Comp1); | |
export default class App extends Component { | |
constructor(props){ | |
super(props); | |
} | |
render(){ | |
return( | |
<div> | |
<WrappedComp1/> | |
</div> | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment