Skip to content

Instantly share code, notes, and snippets.

@Naturalclar
Last active October 29, 2018 23:24
Show Gist options
  • Save Naturalclar/caa6846ba7ff9d6895e95d5db927f189 to your computer and use it in GitHub Desktop.
Save Naturalclar/caa6846ba7ff9d6895e95d5db927f189 to your computer and use it in GitHub Desktop.
React Hooksを触ってみた - State Hooks ref: https://qiita.com/Naturalclar/items/706d10e4d3a442f4e513
import React, { Component } from "react";
import ReactDOM from "react-dom";
class App extends Component {
constructor() {
super();
this.state = { count: 0 };
}
setCount(val) {
this.setState({ count: val });
}
render() {
const { count } = this.state;
return (
<div>
<p>You clicked {count} times </p>
<button onClick={() => this.setCount(count + 1)}>Click me</button>
</div>
);
}
}
const rootElement = document.getElementById("root");
ReactDOM.render(<App />, rootElement);
yarn add react@next react-dom@next
const [count, setCount] = useState(0)
const [count, setCount] = useState(0)
<button onClick={() => setCount(count + 1)}>Click me</button>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment