-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.js
57 lines (46 loc) · 1.19 KB
/
App.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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import React from 'react';
let Mixin = InnerComponent => class extends React.Component {
constructor() {
super();
this.update = this.update.bind(this);
this.state = {val: 0};
}
update() {
this.setState({val: this.state.val + 1});
}
componentWillMount() {
console.log('will mount');
}
render() {
return <InnerComponent
update={this.update}
{...this.state}
{...this.props} />
}
componentDidUpdate() {
console.log('mounted');
}
};
const Button = (props) => <button
onClick={props.update}>
{props.txt} - {props.val}
</button>;
const Label = (props) => <label
onMouseMove={props.update}>
{props.txt} - {props.val}
</label>;
let ButtonMixed = Mixin(Button);
let LabelMixed = Mixin(Label);
class App extends React.Component {
render() {
return (
<div>
<ButtonMixed txt="Button"/>
<LabelMixed txt="Label"/>
</div>
)
}
}
// Default props value
App.defaultProps = {txt: 'button'};
export default App