1.0.0 • Published 4 years ago

use-em-to-px v1.0.0

Weekly downloads
6
License
-
Repository
github
Last release
4 years ago

use-em-to-px

npm version

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.