1.0.3 • Published 4 years ago
@joecritch/use-contain v1.0.3
use-contain
Install
npm:
npm install --save use-contain
yarn:
yarn add use-contain
Usage
import React, { Component } from 'react';
import { useContain } from 'use-contain';
const Example = () => {
const { dimensions, ref } = useContain({
aspectRatio: 16 / 9,
});
return (
<div ref={ref} style={{ width: 500, height: 500 }}>
<div
style={{
width: dimensions?.width || undefined,
height: dimensions?.height || undefined,
}}
>
{dimensions && `${dimensions.width} x ${dimensions.height}`}
</div>
</div>
);
};
License
MIT © joecritch
This hook is created using create-react-hook.