Develop ultra fast with Prismane 🎉

useDimensions

useDimensions hook provides a simple way to get the dimensions of an element.

Import

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

Usage

function Demo() {
  const ref = useRef(null);

  const dimensions = useDimensions(ref);

  return (
    <Flex direction="column" gap={fr(5)}>
      <Box w={fr(50)} h={fr(40)} p={fr(5)} m={fr(2)} bg="primary" ref={ref} />
      <List>
        {dimensions &&
          Object.entries(dimensions).map(([key, value]) => (
            <List.Item key={key}>
              <Text as="strong">{key}:</Text>{" "}
              {typeof value === "object" ? JSON.stringify(value) : value}
            </List.Item>
          ))}
      </List>
    </Flex>
  );
}

API

Parameters

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

Return Value

NameTypeDescription
debouncedanyThe debounced value.