Skip to content

Is it working for functional components?Β #23

@spidgorny

Description

@spidgorny

I'm trying to test it with functional components, but don't seem to notice any effect.

import { useEffect, useState } from 'react';
// @ts-ignore
import debounceRender from 'react-debounce-render';

export function Debounce() {
	const [counter, setCounter] = useState(0);

	useEffect(() => {
		window.requestAnimationFrame(() => {
			setCounter(counter + 1);
		});
	});

	return <p>{counter}</p>;
}

export default debounceRender(Debounce, 1000, { maxWait: 1000 });

In my tests it keeps counting every frame. Desired effect: counting once per second. Using React 17.0.1.
What's wrong?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions