Skip to content

Instantly share code, notes, and snippets.

@Ami777
Created March 2, 2017 11:12
Show Gist options
  • Save Ami777/d48ae8207ff7543f763ff6d1813a28b6 to your computer and use it in GitHub Desktop.
Save Ami777/d48ae8207ff7543f763ff6d1813a28b6 to your computer and use it in GitHub Desktop.
import React from 'react';
import ReactDOM from 'react-dom';
document.addEventListener('DOMContentLoaded', function(){
class ShowInfo extends React.Component {
render() {
return <h1>{ this.props.info }</h1>;
}
}
class PropsToState extends React.Component {
constructor(props) {
super(props);
this.state = {
text: this.props.text,
};
}
componentDidMount(){
this.intervalId = setInterval(() => {
this.setState({
text : this.state.text + '.',
});
}, 1000);
}
componentWillUnmount(){
clearInterval( this.intervalId );
}
render() {
return <ShowInfo info={this.state.text}/>
}
}
class App extends React.Component {
render(){
return <PropsToState text="Sialalal" />;
}
}
ReactDOM.render(
<App />,
document.getElementById('app')
);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment