Skip to content

Latest commit

 

History

History
32 lines (22 loc) · 623 Bytes

README.md

File metadata and controls

32 lines (22 loc) · 623 Bytes

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.