-
Notifications
You must be signed in to change notification settings - Fork 0
/
HOC.js
30 lines (27 loc) · 901 Bytes
/
HOC.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import React from 'react'
// This is the tut for Higher Order Component . this reduces the code rewriting .
const updatedComponent = OriginalComponent => {
class NewComponent extends React.Component {
constructor(props) {
super(props)
this.state = {
hovor: 0
}
}
// this.setState(prevState => {
// return { hovor: prevState.hovor + 1 }
// } this is also valid .
HoverChange = () => {
this.setState({
hovor: this.state.hovor + 1
}
)
}
render() {
return <OriginalComponent hovor={this.state.hovor} HoverChange= {this.HoverChange}
{...this.props}/> // now ... this is used to pass remaining args.
}
}
return NewComponent;
}
export default updatedComponent