- 原本的寫法
const input = this.props.long ? <textarea
onChange={this.props.onChange}
className="make-this-pretty"
id="important-input"
name="important-input"
/> : <input
onChange={this.props.onChange}
className="make-this-pretty"
id="important-input"
name="important-input"
/>;
- 改進的寫法
const Tag = this.props.long ? "textarea" : "input";
const input = <Tag
onChange={this.props.onChange}
className="make-this-pretty"
id="important-input"
/>;