Perform debounce in React.js

前端 未结 30 2135
礼貌的吻别
礼貌的吻别 2020-11-22 04:11

How do you perform debounce in React.js?

I want to debounce the handleOnChange.

I tried with debounce(this.handleOnChange, 200) but it doesn\'t

30条回答
  •  猫巷女王i
    2020-11-22 04:44

    Lots of good info here already, but to be succinct. This works for me...

    import React, {Component} from 'react';
    import _ from 'lodash';
    
    class MyComponent extends Component{
          constructor(props){
            super(props);
            this.handleChange = _.debounce(this.handleChange.bind(this),700);
          }; 
    

提交回复
热议问题