[react] 动态JSX标签


  • 原本的写法
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"
              />;


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM