Skip to content

fitContainer

Get the width and height for an element based on its aspect ratio and the container to fit in a such a way the aspect ratio of the element is not compromised.

Type Definition

NameTypeDescription
aspectRationumberAspect ratio of the element to fit.
containerSizeVector<number>Width and height of the container.

How to use

js
const container = useWindowDimensions();
const resolution = { width: 1920, height: 1080 };
const size = fitContainer(resolution.width / resolution.height, {
  width: container.width,
  height: container.height,
});

Released under the MIT License.