美文网首页
七、React用到的修饰器

七、React用到的修饰器

作者: 懒羊羊3号 | 来源:发表于2018-12-29 10:10 被阅读0次

    1、input事件会报错,因为事件合成
    http://billqiu.github.io/2017/10/15/how-to-debounce-in-react/

    普通写法

    import debounce from 'lodash/debounce';
    
      constructor(props) {
        super(props);
        this.debounceHandleChange = debounce(this.debounceHandleChange, 2000);
      }
    
      debounceHandleChange(value) {
        console.log(value);
      };
    
      handleChange = (e) => {
        e.persist();
        this.debounceHandleChange(e.target.value)
        //this.requestNodeListLatest(e.target.value);
      };
    

    修饰器写法

    import { Debounce, Bind} from 'lodash-decorators';
    
      @Debounce(2000)
      debounceHandleChange(value) {
        console.log(value);
      };
      handleChange = (e) => {
        e.persist();
        this.debounceHandleChange(e.target.value)
      };
    

    2、antd表单From的用法

    第一种
    const EditableFormRow = Form.create()(EditableRow);
    第二种
    @Form.create()
    

    3、使用redux

    @connect(({global}) => ({user:global.user}))
    

    相关文章

      网友评论

          本文标题:七、React用到的修饰器

          本文链接:https://www.haomeiwen.com/subject/vbizqqtx.html