Skip to content

Instantly share code, notes, and snippets.

View tpae's full-sized avatar

Terence Pae tpae

  • San Francisco, CA
  • X @tpae
View GitHub Profile
@nwatab
nwatab / LazyCardMedia.tsx
Created August 17, 2020 00:20
Lazy load image in Material-UI Card Media
import React, {useState, useEffect, useRef} from 'react'
import { CardMedia } from '@material-ui/core'
interface ICardMediaProp {
component: string,
image: string,
alt: string,
height: string,
}
export default (props: ICardMediaProp) => {
@paulirish
paulirish / what-forces-layout.md
Last active May 12, 2024 13:20
What forces layout/reflow. The comprehensive list.

What forces layout / reflow

All of the below properties or methods, when requested/called in JavaScript, will trigger the browser to synchronously calculate the style and layout*. This is also called reflow or layout thrashing, and is common performance bottleneck.

Generally, all APIs that synchronously provide layout metrics will trigger forced reflow / layout. Read on for additional cases and details.

Element APIs

Getting box metrics
  • elem.offsetLeft, elem.offsetTop, elem.offsetWidth, elem.offsetHeight, elem.offsetParent