Last active
October 29, 2018 23:24
-
-
Save Naturalclar/caa6846ba7ff9d6895e95d5db927f189 to your computer and use it in GitHub Desktop.
React Hooksを触ってみた - State Hooks ref: https://qiita.com/Naturalclar/items/706d10e4d3a442f4e513
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 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); |
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
yarn add react@next react-dom@next |
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
const [count, setCount] = useState(0) |
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
const [count, setCount] = useState(0) |
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
<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