<div id="example"></div>
<script type="text/babel">
var Ajaxs=React.createClass({
getInitialState:function(){
return{
username:'',
lastGistUrl:''
};
},
componentDidMount:function(){
/* 通过Ajax获取组件中的数据*/
this.serverRequest= $.get(this.props.source,function(result){
var lastGist=result[0];
this.setState({
lastGistUrl:lastGist.html_url
});
}.bind(this))
},
componentWillUnmount:function(){
/*异常退出*/
this.serverRequest.abort();
},
render:function(){
return(
<div>
用户最新的Gist共享地址:
<a href={this.state.lastGistUrl}>{this.state.lastGistUrl}</a>
</div>
)
}
});
ReactDOM.render(
<Ajaxs source="https://api.github.com/users/octocat/gists"/>,
document.getElementById('example')
);
</script>