React.js throttle mousemove event keep throwing event.persist() error

前端 未结 2 1465
青春惊慌失措
青春惊慌失措 2021-02-01 23:53

I need to throttle the mousemove event, and I follow the tips below to build the method, but doesn\'t work: Perform debounce in React.js

Here is my code (http://jsbin.co

2条回答
  •  星月不相逢
    2021-02-02 00:13

    With hooks:

    const Tool = () => {
      const onMouseMove = useMemo(() => {
        const throttled = _.throttle(e => console.log(e.screenX), 300);
        return e => {
          e.persist();
          return throttled(e);
        };
      }, []);
      return (
        
    Content
    ); };

提交回复
热议问题