Skip to content

🏹 A React hook used to convert em units to pixels in the most precise way

Notifications You must be signed in to change notification settings

itayganor/use-em-to-px

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

About

🏹 A React hook used to convert em units to pixels in the most precise way

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published