Skip to content

Instantly share code, notes, and snippets.

@dan-tenovski
Created August 3, 2017 23:16
Show Gist options
  • Save dan-tenovski/94ec25941a89cad8d6628c26d0ad2f43 to your computer and use it in GitHub Desktop.
Save dan-tenovski/94ec25941a89cad8d6628c26d0ad2f43 to your computer and use it in GitHub Desktop.
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