-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Render Props
- Loading branch information
Showing
5 changed files
with
76 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import React, { Component } from "react"; | ||
|
||
class ClickCounterTwo extends Component { | ||
render() { | ||
const { count, incrementCount } = this.props; | ||
return ( | ||
<div> | ||
<button onClick={incrementCount}>Clicked {count} times</button> | ||
</div> | ||
); | ||
} | ||
} | ||
|
||
export default ClickCounterTwo; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import React, { Component } from "react"; | ||
|
||
class HoverCounterTwo extends Component { | ||
render() { | ||
const { count, incrementCount } = this.props; | ||
return ( | ||
<div> | ||
<h1 onMouseOver={incrementCount}>Hover {count} times</h1> | ||
</div> | ||
); | ||
} | ||
} | ||
|
||
export default HoverCounterTwo; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import React, { Component } from "react"; | ||
|
||
class Increment extends Component { | ||
constructor(props) { | ||
super(props); | ||
|
||
this.state = { | ||
count: 0, | ||
}; | ||
} | ||
|
||
incrementCount = () => { | ||
this.setState((prevState) => { | ||
return { count: prevState.count + 1 }; | ||
}); | ||
}; | ||
|
||
render() { | ||
return ( | ||
<div>{this.props.render(this.state.count, this.incrementCount)}</div> | ||
); | ||
} | ||
} | ||
|
||
export default Increment; | ||
|
||
/* | ||
Sharing common functionality between components. | ||
The term "render prop" refers to a technique for sharing code between React components using a prop whosevalue is a function. | ||
*/ |