Skip to content

Commit f5c4d10

Browse files
committed
ReactJS Tutorial - 13 - Event Handling
1 parent 37c4280 commit f5c4d10

File tree

6 files changed

+101
-26
lines changed

6 files changed

+101
-26
lines changed

src/App.js

+16-12
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,27 @@ import Hello from './components/Hello';
66
import Message from './components/Message';
77
import Counter from './components/Counter'
88
import Setstate from './components/Setstate';
9+
import FunctionClick from './components/FunctionClick';
10+
import ClassClick from './components/ClassClick';
911

1012
function App() {
1113
return (
1214
<div className="App">
15+
16+
<FunctionClick/>
17+
<ClassClick/>
18+
{/* <Setstate/> */}
19+
{/* <Counter/> */}
20+
{/* <Message/> */}
21+
{/* { <Greet name="Bruce" heroName="Batman" />
22+
<Greet name="Clark" heroName="Superman"/> */}
23+
{/* <Greet name="Diana" heroName="wonder Woman" /> */}
1324

14-
<Setstate/>
15-
16-
{/* <Counter/> */}
17-
{/* <Message/> */}
18-
{/* <Greet name="Bruce" heroName="Batman" />
19-
<Greet name="Clark" heroName="Superman"/>
20-
<Greet name="Diana" heroName="wonder Woman" />
21-
22-
< Welcome name="Bruce" heroName="Batman" />
23-
< Welcome name="Clark" heroName="Superman"/>
24-
< Welcome name="Diana" heroName="wonder Woman" /> */}
25-
{/* <Hello/> */}
25+
{/* < Welcome name="Bruce" heroName="Batman" /> */}
26+
27+
{/* < Welcome name="Clark" heroName="Superman"/>
28+
< Welcome name="Diana" heroName="wonder Woman" /> */}
29+
{/* <Hello/> */}
2630
</div>
2731
);
2832
}

src/components/ClassClick.js

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import React, { Component } from 'react'
2+
3+
class ClassClick extends Component {
4+
5+
// METHOD
6+
7+
clickHandler(){
8+
console.log('Clicked the button')
9+
}
10+
11+
12+
13+
render() {
14+
return (
15+
<div>
16+
<button onClick = {this.clickHandler}>Click me</button>
17+
</div>
18+
)
19+
}
20+
}
21+
22+
export default ClassClick
23+
24+

src/components/Counter.js

+11-5
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,22 @@ constructor(props) {
66
super(props)
77

88
this.state = {
9-
count: 0,
10-
name: ''
9+
count: 0
10+
1111
}
1212
}
1313

1414
increment() {
15-
const updatedCount = this.state.count + 1;
16-
this.setState({count: updatedCount});
15+
this.setState({
16+
count: this.state.count + 1
17+
},
18+
() => {
19+
console.log('Callback value', this.state.count )
20+
}
1721

18-
console.log(updatedCount);
22+
);
23+
24+
console.log(this.state.count);
1925
}
2026

2127
render() {

src/components/FunctionClick.js

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import React from 'react'
2+
3+
function FunctionClick() {
4+
5+
function clickHandler (){
6+
console.log('Button clicked')
7+
}
8+
9+
return (
10+
<div>
11+
<button onClick={clickHandler}>Click</button>
12+
</div>
13+
)
14+
}
15+
16+
export default FunctionClick

src/components/Welcome.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@
22

33
class Welcome extends Component {
44
render() {
5+
const { name, heroName} = this.props
6+
// const {state1, state2}= this.state
57
return(
68
<h1>
7-
Welcome {this.props.name} a.k.a {this.props.heroName}
9+
Welcome {name} a.k.a {heroName}
810
</h1>
911

1012
);

src/components/greet.js

+31-8
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,34 @@ import React from 'react';
66
// );
77
// }
88

9-
export const Greet = props => {
10-
console.log(props);
11-
return(
12-
<h1>Hello {props.name} a.k.a {props.heroName} </h1>
13-
);
14-
}
15-
16-
// export default Greet;
9+
// // export const Greet = ({name,heroName}) => {
10+
11+
// // return(
12+
// // <div>
13+
// // <h1>
14+
// // Hello {name} a.k.a {heroName}
15+
// // </h1>
16+
// // </div>
17+
// // );
18+
// }
19+
20+
export const Greet = props => {
21+
const {name , heroName} = props
22+
return(
23+
<div>
24+
<h1>
25+
Hello {name} a.k.a {heroName}
26+
</h1>
27+
</div>
28+
);
29+
}
30+
31+
32+
33+
34+
35+
36+
37+
38+
39+

0 commit comments

Comments
 (0)