# All files / utils useLayoutStyle.ts

15.38% Statements 2/13
0% Branches 0/2
0% Functions 0/2
25% Lines 2/8

Press n or j to go to the next uncovered block, b, p or k for the previous block.

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    191x

    1x

     import {useLayoutEffect, CSSProperties} from 'react'

    export const useLayoutStyle = (
      el: HTMLElement,
      f: (el: HTMLElement) => CSSProperties
    ) => {
      useLayoutEffect(() => {
        if (!el) {
          return
        }

        const style = f(el)

        for (const [k, v] of Object.entries(style)) {
          el.style[k] = v
        }
      })
    }