diff --git a/src/App.js b/src/App.js index 4cde872d97d489b2b16588b514f9f91a206121fa..a19d568b95bfa4966ad84ecd996352194fff5cc3 100755 --- a/src/App.js +++ b/src/App.js @@ -1,11 +1,39 @@ import React, { Component } from 'react'; -const App = () => { +const cityList = [ + {cityName: "Seoul", timezone: "Asia/Seoul"}, + {cityName: "London", timezone: "Europe/London"}, + {cityName: "NewYork", timezone: "America/New_York"}, +]; + +const TimeButton = (props) => { + let [time,setTime] = useState(null); + const displayTime = () => { + let date = new Date(); + setTime(date.toLocaleString("ko-KR", { timeZone: props.tz })); + }; + + return ( + <> + <button onClick={displayTime} tz={props.tz}>{props.name}</button> + <div id='time'>{time}</div> + </> + ); +} + +const App = (props) => { + let city = cityList.map((value => { + console.log(value.cityName); + return <TimeButton name={value.cityName} tz={value.timezone} />; + })); + return ( + <> <h1> What time is it? </h1> + </> ); } -export default App; +export default App; \ No newline at end of file