-
Notifications
You must be signed in to change notification settings - Fork 0
/
code-defaultProps.js
47 lines (42 loc) · 1.07 KB
/
code-defaultProps.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
"use strict"
require("./node_modules/bootstrap/dist/css/bootstrap.min.css")
import React, { Component, PropTypes, DefaultProps } from 'react'
import ReactDOM from 'react-dom'
export default class Button extends Component {
constructor (props) {
super(props)
this.state = { }
}
render () {
return <button onClick={this.props.myRequiredFunction}>{this.props.buttonLabel}</button>
}
}
// ES6 static vars for getDefaultProps - must be defined outside class
// ES7 can be set inside class defenition ie. static propTypes = {}
Button.propTypes = {
buttonLabel: React.PropTypes.string,
myRequiredFunction: React.PropTypes.func.isRequired
}
Button.defaultProps = {
buttonLabel: 'Submit',
myRequiredFunction: () => { console.log('myRequiredFunction called!'); }
}
export default class Content extends Component {
constructor (props) {
super(props)
}
render () {
return (
<div>
<Button buttonLabel="Start"/>
<Button />
<Button />
<Button />
</div>
)
}
}
ReactDOM.render(
<Content />,
document.getElementById('content')
)