Skip to content

Instantly share code, notes, and snippets.

@eduard-tkv
Created April 14, 2017 18:08
Show Gist options
  • Save eduard-tkv/3105e2e730dff1df6df0cb451f7213bd to your computer and use it in GitHub Desktop.
Save eduard-tkv/3105e2e730dff1df6df0cb451f7213bd to your computer and use it in GitHub Desktop.
let HigherOrderComp = (Component) => class extends React.Component{
construstor(props){
super(props);
this.state = {
count: 0
};
}
componentDidMount(){
setInterval(()=>{
this.setState(
count: this.state.count + 1
);
}, 1000)
}
render(){
return <Component {...this.props} {...this.state}>
}
}
class Comp1 extends React.Component{
render(){
return(
<div>
<p>Comp1</p>
</div>
);
}
}
let Wrapped1 = HigherOrderComp(Comp1);
class App extends React.Component{
constructor(props){
super(props);
}
render(){
return(
<div>
<Wrapped1/>
</div>
);
}
}
ReactDOM.render(<App/>, document.getElementById('app'));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment