File tree 1 file changed +41
-0
lines changed
1-exercise-solutions/lesson-04
1 file changed +41
-0
lines changed Original file line number Diff line number Diff line change
1
+ <!DOCTYPE html>
2
+ < html >
3
+ < head >
4
+ < title > React Basics</ title >
5
+ < style >
6
+ </ style >
7
+ </ head >
8
+ < body >
9
+ < div class ="js-container "> </ div >
10
+
11
+ < script src ="https://unpkg.com/supersimpledev/dayjs.js "> </ script >
12
+
13
+ < script src ="https://unpkg.com/supersimpledev/react.js "> </ script >
14
+ < script src ="https://unpkg.com/supersimpledev/react-dom.js "> </ script >
15
+
16
+ < script src ="https://unpkg.com/supersimpledev/babel.js "> </ script >
17
+ < script type ="text/babel ">
18
+ function App ( ) {
19
+ const [ time , setTime ] = React . useState (
20
+ dayjs ( ) . format ( 'HH:mm:ss' )
21
+ ) ;
22
+
23
+ React . useEffect ( ( ) => {
24
+ setInterval ( ( ) => {
25
+ setTime ( dayjs ( ) . format ( 'HH:mm:ss' ) ) ;
26
+ } , 1000 ) ;
27
+
28
+ // Important: make sure to give React.useEffect()
29
+ // a dependency array of [] so it only runs once!
30
+ } , [ ] ) ;
31
+
32
+ return (
33
+ < p > Current time: { time } </ p >
34
+ ) ;
35
+ }
36
+
37
+ const container = document . querySelector ( '.js-container' ) ;
38
+ ReactDOM . createRoot ( container ) . render ( < App /> ) ;
39
+ </ script >
40
+ </ body >
41
+ </ html >
You can’t perform that action at this time.
0 commit comments