-
Notifications
You must be signed in to change notification settings - Fork 2
/
validating-properties-jsx.html
45 lines (39 loc) · 1.15 KB
/
validating-properties-jsx.html
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
<!doctype html>
<html lang="en">
<head>
<script type="text/javascript" src="react-0.8.0/build/react.js"></script>
<script type="text/javascript" src="react-0.8.0/build/JSXTransformer.js"></script>
</head>
<body>
<script type="text/jsx">
/**
* @jsx React.DOM
*/
var InterfaceComponent = React.createClass({
propTypes: {
name : React.PropTypes.string,
visible : React.PropTypes.bool.isRequired,
before : function(props, propName, componentName) {
if (!(propName in props)) {
throw new Error("before must be set.");
}
var now = new Date();
if (now.getTime() >= props[propName].getTime()) {
throw new Error("before must be set to a later date.");
}
}
},
render : function() {
return <div>hello {this.props.name}!</div>;
}
});
React.renderComponent(
<InterfaceComponent
name="chris"
visible={true}
before={new Date(Date.now() + 10000)} />,
document.body
);
</script>
</body>
</html>