Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions hooks/src/App.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import React from 'react'
import './App.css';
import ClassCounter from "./components/ClassCounter";
import HookCounter from "./components/HookCounter";
import './App.css'
import IntervalClassCounter from "./components/IntervalClassCounter";
import IntervalHookCounter from "./components/IntervalHookCounter";

function App() {
return (
<div className="App">
{/*<ClassCounter/>*/}
<HookCounter/>
</div>
);
return (
<div className='App'>
<IntervalClassCounter/>
<IntervalHookCounter/>
</div>
)
}

export default App;
export default App
28 changes: 0 additions & 28 deletions hooks/src/components/ClassCounter.js

This file was deleted.

16 changes: 0 additions & 16 deletions hooks/src/components/HookCounter.js

This file was deleted.

30 changes: 30 additions & 0 deletions hooks/src/components/IntervalClassCounter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import React, { Component } from 'react'

class IntervalClassCounter extends Component {
constructor(props){
super(props)
this.state = {
count: 0
}
}

componentDidMount() {
this.interval = setInterval(this.tick,1000)
}

componentWillUnmount() {
clearInterval(this.interval)
}

tick = () => {
this.setState({
count: this.state.count + 1
})
}

render() {
return <h1>{this.state.count}</h1>
}
}

export default IntervalClassCounter
32 changes: 32 additions & 0 deletions hooks/src/components/IntervalHookCounter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import React,{useState,useEffect} from 'react'

function IntervalHookCounter() {
const [count,setCount] =useState(0)

const tick = () => {
setCount(count + 1)
}


useEffect(() => {
function doSomething() {

}
doSomething()
const interval = setInterval(tick,1000)
return() => {
clearInterval(interval)
}
},)

return(
<div>
{count}
</div>
)

}

export default IntervalHookCounter

//カウンターの道理はまだ理解出来ていない(9/23現在)為、使うことがあったら再度戻っての復習を行う。