七、React用到的修饰器

2018-12-29  本文已影响0人  懒羊羊3号

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}))
上一篇下一篇

猜你喜欢

热点阅读