Skip to content

Latest commit

 

History

History
26 lines (19 loc) · 636 Bytes

debounce.md

File metadata and controls

26 lines (19 loc) · 636 Bytes

notes on debounce

This worked, to do auto/align when the user stops typing. It only calls it once.

Outside of the component

import pDebounce from 'p-debounce';
...
const debouncedSave = pDebounce(updateBloocksTimestamps, 3000);

inside the component keydown

const handleOnKeyDown = async (event) => {
      ...
  // value is the content of slateJS
  const alignedSlateData = await debouncedSave(value);
  setValue(alignedSlateData);
  setIsContentIsModified(false);

seems like having it inside the component was being effected by the components re-renders.

This could be used for pause while typing as well.