Skip to content

Instantly share code, notes, and snippets.

@monkindey
Created August 16, 2017 02:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save monkindey/ea2d1cb48b2b7b0b3d99ef3f227716f1 to your computer and use it in GitHub Desktop.
Save monkindey/ea2d1cb48b2b7b0b3d99ef3f227716f1 to your computer and use it in GitHub Desktop.
getter just like vue computed property
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