File tree 1 file changed +20
-19
lines changed
1 file changed +20
-19
lines changed 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
- class Counter extends React . Component {
5
- constructor ( props ) {
6
- super ( props ) ;
7
- this . state = { count : 0 } ;
8
- }
4
+ const Counter = ( ) => {
5
+ const [ count , setCount ] = useState ( 0 ) ;
9
6
10
7
increment = ( ) => {
11
- const { count} = this . state ;
12
- this . setState ( { count : count + 1 } ) ;
13
- }
8
+ setCount ( prevCount => prevCount + 1 ) ;
9
+ } ;
14
10
15
- render ( ) {
16
- const { count} = this . state ;
17
- return (
18
- < div id = "mainArea" >
19
- < p > button count: < span > { count } </ span > </ p >
20
- < button onClick = { this . increment } id = "mainButton" > Increase</ button >
21
- </ div >
22
- ) ;
23
- }
24
- }
11
+ return (
12
+ < div id = "mainArea" >
13
+ < p >
14
+ Button Count:
15
+ < span > { count } </ span >
16
+ </ p >
17
+ < button
18
+ onClick = { increment }
19
+ id = "mainButton"
20
+ >
21
+ Increase
22
+ </ button >
23
+ </ div >
24
+ ) ;
25
+ } ;
25
26
26
27
ReactDOM . render (
27
28
< Counter /> ,
You can’t perform that action at this time.
0 commit comments