use-em-to-px
v1.0.0
Published
A React hook used to convert em units to pixels in the most precise way
Downloads
3
Readme
use-em-to-px
Not your regular em
to px
converter.
Install
npm install use-em-to-px
Usage
import useEmToPx from 'use-em-to-px';
function Foo() {
const [ref, emToPx] = useEmToPx<HTMLDivElement>();
return <div ref={ref}>
In this div, 1em is equal to {emToPx(1)}.
</div>;
}
In CSS, em
sizes are calculated relative to the current font size. The hook returns a reference
To measure font size by, and a function that calculates the exact size in px
.
Uses 16px
as a fallback.