Skip to content

Instantly share code, notes, and snippets.

@h4091
Last active December 28, 2018 14:58
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 h4091/9fc978114eeea475f0a8101e0c1ec16e to your computer and use it in GitHub Desktop.
Save h4091/9fc978114eeea475f0a8101e0c1ec16e to your computer and use it in GitHub Desktop.
Test10
<div id="root"></div>
function FormattedDate(props) {
return <h2>It is {props.date.toLocaleTimeString()}.</h2>
}
// Clock component
class Clock extends React.Component {
constructor(props) {
super(props);
this.state = {date: new Date()};
}
// Mounting
componentDidMount() {
this.timerID = setInterval(
() => this.tick(),
1000
);
}
// Unmounting
componentWillUnmount() {
clearInterval(this.timerID);
}
tick() {
this.setState({
date: new Date()
});
}
render() {
return (
<div>
<h1>Hello world!</h1>
<FormattedDate date={this.state.date} />
</div>
);
}
}
function App(){
return (
<div>
<Clock />
<Clock />
<Clock />
</div>
);
}
ReactDOM.render(
<App />,
document.getElementById("root")
);
<script src="https://unpkg.com/react/umd/react.development.js"></script>
<script src="https://unpkg.com/react-dom/umd/react-dom.development.js"></script>

Test10

Learn the fundamentals of React, including simple and class components, state, props, and submitting form data.

State & Lifecycle

A Pen by 你银子掉了 on CodePen.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment