Skip to content

Instantly share code, notes, and snippets.

@dejanbatanjac
Created January 29, 2017 11:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dejanbatanjac/927f86c43c63368efa9322c1f26e387d to your computer and use it in GitHub Desktop.
Save dejanbatanjac/927f86c43c63368efa9322c1f26e387d to your computer and use it in GitHub Desktop.
react with the timer
import React from "react";
import ReactDOM from "react-dom";
class Footer extends React.Component{
constructor(props){
super(props);
this.state={ time: 1 }
//this.updater = this.updater.bind(this);
this.handleClick = this.handleClick.bind(this);
}
handleClick() {
setInterval(() => this.setState({time: this.state.time + 1}), 1000);
console.log("Handler5");
}
componentDidMount(){
this.handleClick();
}
render() {
return (
<div>
Hello... {this.state.time}
</div>
);
}
}
class Text extends React.Component{
constructor(props){
super(props);
}
render() {
return (
<div>
Hello... {this.props.text}
</div>
);
}
}
class SmartCo extends React.Component {
constructor() {
super();
this.state = {
title: '',
};
}
ch(e) {
console.log(e.target.value);
this.setState({title : e.target.value })
}
render() {
return (
<div>
<Text text={this.state.title} />
<input onChange={this.ch.bind(this)}/>
<Footer />
</div>
);
}
}
//--
const app = document.getElementById('app');
ReactDOM.render(<SmartCo/>, app);
import React from "react";
import ReactDOM from "react-dom";
class Footer extends React.Component{
constructor(props){
super(props);
this.state={ time: 1 }
//this.updater = this.updater.bind(this);
this.handleClick = this.handleClick.bind(this);
}
handleClick() {
setInterval(() => this.setState({time: this.state.time + 1}), 1000);
console.log("Handler5");
}
componentDidMount(){
this.handleClick();
}
render() {
return (
<div>
Hello... {this.state.time}
</div>
);
}
}
class Text extends React.Component{
constructor(props){
super(props);
}
render() {
return (
<div>
Hello... {this.props.text}
</div>
);
}
}
class SmartCo extends React.Component {
constructor() {
super();
this.state = {
title: '',
};
}
ch(e) {
console.log(e.target.value);
this.setState({title : e.target.value })
}
render() {
return (
<div>
<Text text={this.state.title} />
<input onChange={this.ch.bind(this)}/>
<Footer />
</div>
);
}
}
//--
const app = document.getElementById('app');
ReactDOM.render(<SmartCo/>, app);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment