Develop ultra fast with Prismane 🎉

useDebounce

useDebounce hook provides a simple way to debounce heavy calculations.

Import

import { useDebounce } from "@prismane/core/hooks";

Usage

function Demo() {
  const [value, setValue] = useState("");

  const debounced = useDebounce(value, 1000);

  return (
    <Flex direction="column" gap={fr(5)}>
      <Field
        value={value}
        onChange={(e) => setValue(e.target.value)}
        placeholder="Debounce Field"
      />
      <Text
        cl={(theme) => (theme.mode === "dark" ? ["base", 200] : ["base", 700])}
      >
        {debounced}
      </Text>
    </Flex>
  );
}

API

Parameters

NameTypeDescriptionDefault
valueanyThe value that should be debounced.-
delaynumberThe debounce delay.500

Return Value

NameTypeDescription
debouncedanyThe debounced value.