File tree Expand file tree Collapse file tree 2 files changed +19
-2
lines changed Expand file tree Collapse file tree 2 files changed +19
-2
lines changed Original file line number Diff line number Diff line change 6
6
< body >
7
7
< h1 > Hello world</ h1 >
8
8
< div id ='app '> </ div >
9
+ < button id ='myBtn '> hello btn</ button >
10
+ < script >
11
+ var btn = document . getElementById ( "myBtn" )
12
+ btn . addEventListener ( 'click' , ( event ) => {
13
+ alert ( "Button clicked." )
14
+ } )
15
+ </ script >
9
16
< script src ='index.js '> </ script >
10
17
</ body >
11
18
</ html >
Original file line number Diff line number Diff line change 1
- import React from 'react'
1
+ import React , { useState } from 'react'
2
2
import ReactDOM from 'react-dom'
3
3
4
4
5
+ const Btn = ( ) => {
6
+ const [ clickCount , setClickCount ] = useState ( 0 )
7
+
8
+ const handleClick = ( event ) => {
9
+ // alert("btn in react")
10
+ setClickCount ( clickCount + 1 )
11
+ }
12
+ return < button onClick = { handleClick } className = { `class-${ clickCount } ` } > hello react btn</ button >
13
+ }
14
+
5
15
const App = ( ) => {
6
- return < div > Hello world again.</ div >
16
+ return < div > Hello world again.< Btn /> < /div >
7
17
}
8
18
9
19
const htmlElement = document . getElementById ( "app" )
You can’t perform that action at this time.
0 commit comments