Skip to content

Commit

Permalink
💸 Methods as Props
Browse files Browse the repository at this point in the history
Methods as Props
  • Loading branch information
SaishJ committed Aug 25, 2022
1 parent 6999a5a commit 7b5eae4
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 1 deletion.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -187,3 +187,5 @@ class ClassClick extends Component {

export default ClassClick;
```

### [Binding Event Handlers](https://github.com/SaishJ/React-JS-Beginner-to-Advanced/commit/6999a5a35a3c163f62a3918ce5e47ebeb38d02dc#diff-d8e2fd228629da81ebb95e75620e3bff49619c19c32244fdeea37f9b0b365ec7)
4 changes: 3 additions & 1 deletion src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@ import Counter from "./components/counter";
import FunctionClick from "./components/FunctionClick";
import ClassClick from "./components/ClassClick";
import EvenBind from "./components/EventBind";
import ParentComponent from "./components/ParentComponent";

function App() {
return (
<div className="App">
<EvenBind />
<ParentComponent />
{/* <EvenBind /> */}
{/* <FunctionClick /> */}
{/* <ClassClick /> */}
{/* <Counter /> */}
Expand Down
11 changes: 11 additions & 0 deletions src/components/ChildComponent.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import React from "react";

function ChildComponent(props) {
return (
<div>
<button onClick={() => props.greetHandler("child")}>Greet Parent</button>
</div>
);
}

export default ChildComponent;
28 changes: 28 additions & 0 deletions src/components/ParentComponent.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import React, { Component } from "react";
import ChildComponent from "./ChildComponent";

class ParentComponent extends Component {
constructor(props) {
super(props);

this.state = {
parentName: "Parent",
};

this.greetParent = this.greetParent.bind(this);
}

greetParent(childName) {
alert(`Hello ${this.state.parentName} from ${childName}`);
}

render() {
return (
<div>
<ChildComponent greetHandler={this.greetParent} />
</div>
);
}
}

export default ParentComponent;

0 comments on commit 7b5eae4

Please sign in to comment.