-
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.
React Event Handling & Control Re Rendering 😍
- Loading branch information
1 parent
81beabc
commit 4f868ed
Showing
3 changed files
with
65 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import React, {Component} from 'react'; | ||
|
||
class Button extends Component { | ||
// Should not use ************************* | ||
shouldComponentUpdate(nextProps, nextState, nextContext) { | ||
const {change: currentChange, local: currentLocal} = this.props; | ||
const {change: nextChange, local: nextLocal} = nextProps; | ||
|
||
return !(currentChange === nextChange && currentLocal === nextLocal); | ||
// return currentChange !== nextChange; | ||
// if (currentChange === nextChange && currentLocal === nextLocal) { | ||
// return false; | ||
// } | ||
// return true; | ||
} | ||
|
||
render() { | ||
console.log('Button component render') | ||
const {change, local} = this.props; | ||
return ( | ||
<div> | ||
<button type='button' onClick={() => change(local)}>Click Here</button> | ||
</div> | ||
); | ||
} | ||
} | ||
|
||
export default Button; |
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