1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
| import React from 'react'; import './App.css';
class WorldClock extends React.Component { constructor(props){ super(props) this.state = { hour: this.props.time, minute : 0, stop : false } this.timer = setInterval(()=>{ this.setState((state)=>( state.minute === 59 ?{hour: state.hour + 1, minute :0} : {minute: state.minute + 1} )) }, 100) } handlingClick = (event) => { console.log(event.target) this.setState({stop: event.target.value}) clearInterval(this.timer); } render(){ return( <div className={"WorldClock"}> <h2> 도시 : {this.props.city} </h2> <p> 시간 : {this.state.hour}시 {this.state.minute}분</p> {/* 1-3. onEvent명을 통해 handling 함수를 부른다. */} <button value={true} onClick={this.handlingClick}>멈춰!</button> </div> ) } }
class App extends React.Component { constructor(props){ super(props) this.cityTimeData= [ ['서울', 10], ['북한', 11], ['도쿄', 12], ['베이징', 1], ] this.state ={ content: '' } } handlingChange = (event) => { this.setState({content: event.target.value}) }
render() { return ( <div className="App"> <h1 className = {'myStyle'}>안녕하세요</h1> <div className= {'post'}> 첫 게시글입니다. {/* 2-3.onEvent명을 통해 handling 함수를 부른다. */} <textarea value={this.state.content} onChange={this.handlingChange}></textarea> </div> {this.cityTimeData.map((citytime,index)=> <WorldClock city={citytime[0]} time ={citytime[1]} key ={index} /> ) } </div> ); } }
export default App;
|