-
Notifications
You must be signed in to change notification settings - Fork 6
/
props.html
46 lines (37 loc) · 1.27 KB
/
props.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
46
<!DOCTYPE html>
<html>
<head>
<meta http-equiv='Content-type' content='text/html; charset=utf-8'>
<title>Basic Example Props</title>
</head>
<body>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/0.13.3/react.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/0.13.3/JSXTransformer.js"></script>
<script type="text/jsx">
var Avatar = React.createClass({
propTypes: {
name: React.PropTypes.string.isRequired,
width: React.PropTypes.number.isRequired,
height: React.PropTypes.number.isRequired
},
render() {
var src='http://canime.files.wordpress.com/2010/05/mask-dtb.jpg';
return (
<div>
<img src={src} width={this.props.width} height={this.props.height} alt="alt" />
<span>{this.props.name}</span>
</div>
);
}
});
var AvatarEl = <Avatar name="Foo" width={100} height={100}/>;
var AvatarComponent = React.render(AvatarEl, document.body);
AvatarComponent.setProps({name: "Bar"}, function(){
alert("AvatarComponent setProps Done!");
});
AvatarComponent.replaceProps({name: "Bar-Foo"}, function(){
alert("AvatarComponent replaceProps Done!");
});
</script>
</body>
</html>