Created
August 16, 2017 02:47
-
-
Save monkindey/ea2d1cb48b2b7b0b3d99ef3f227716f1 to your computer and use it in GitHub Desktop.
getter just like vue computed property
This file contains hidden or 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
import React, { Component } from 'react'; | |
import ReactDOM from 'react-dom'; | |
class Getter extends Component { | |
firstAndLastName() { | |
return `${this.props.firstName} ${this.props.lastName}`; | |
} | |
get fullName() { | |
return `${this.props.firstName} ${this.props.lastName}`; | |
} | |
render() { | |
return ( | |
<div> | |
<h3> | |
fullName is {this.fullName} | |
</h3> | |
<h3> | |
firstAndLastName is {this.firstAndLastName()} | |
</h3> | |
</div> | |
); | |
} | |
} | |
ReactDOM.render( | |
<Getter firstName={'kiho'} lastName={'cham'} />, | |
document.getElementById('app') | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment