Created
July 10, 2016 14:48
-
-
Save daslicht/25c6000ee37ca1a32f827b34284a75a6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import * as React from "react"; | |
| import * as ReactDOM from "react-dom"; | |
| import { CommentForm } from "./CommentForm"; | |
| import { CommentList } from "./CommentList"; | |
| declare let $:any; | |
| export interface CommentBoxProps { data:any, url:any, pollInterval:any } | |
| interface AppState { data:any} | |
| export class CommentBox extends React.Component<CommentBoxProps,AppState>{ | |
| loadCommentsFromServer() { | |
| console.log(this.props); | |
| $.ajax({ | |
| url: this.props.url, | |
| dataType: 'json', | |
| cache: false, | |
| success: function(data) { | |
| this.setState({data: data}); | |
| }.bind(this), | |
| error: function(xhr, status, err) { | |
| console.error(this.props.url, status, err.toString()); | |
| }.bind(this) | |
| }); | |
| } | |
| render() { | |
| return ( | |
| <div className="commentBox"> | |
| <h1>Comments</h1> | |
| <CommentList data={this.state.data} /> | |
| <CommentForm /> | |
| </div> | |
| ); | |
| } | |
| constructor(props: any){ | |
| super(props); | |
| this.state = { data: [] }; | |
| this.loadCommentsFromServer(); | |
| setInterval(this.loadCommentsFromServer, this.props.pollInterval); | |
| } | |
| }; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment