Skip to content

Commit

Permalink
export-button-throttle-debounce
Browse files Browse the repository at this point in the history
  • Loading branch information
LEIYOUSU committed Nov 4, 2024
1 parent 81c394a commit 7373fbf
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,12 @@ function ExportButton({ setHtml }: { setHtml: (html: string) => void }) {
const editor = useEditor();
const [loading, setLoading] = useState(false);

const throttle = (func: () => void, limit: number) => {
const throttle = (func: (...args: any[]) => void, limit: number) => {
let lastFunc: NodeJS.Timeout | null = null;
let lastRan: number | null = null;

return function () {
return function (this: any, ...args: any[]) {
const context = this;
const args = arguments;

if (lastRan === null || Date.now() - lastRan >= limit) {
func.apply(context, args);
Expand Down

0 comments on commit 7373fbf

Please sign in to comment.