Skip to content

Instantly share code, notes, and snippets.

View gielcobben's full-sized avatar
💩
Hi

Giel gielcobben

💩
Hi
View GitHub Profile
@gielcobben
gielcobben / useRect.js
Created October 24, 2019 09:34 — forked from morajabi/useRect.js
useRect — getBoundingClientRect() React Hook with resize handler
import { useLayoutEffect, useCallback, useState } from 'react'
export const useRect = (ref) => {
const [rect, setRect] = useState(getRect(ref ? ref.current : null))
const handleResize = useCallback(() => {
if (!ref.current) {
return
}
@gielcobben
gielcobben / personal-raf-boilerplate.js
Created January 21, 2018 17:19 — forked from bendc/personal-raf-boilerplate.js
requestAnimationFrame boilerplate code
"use strict";
// animation utils
// ===============
const trackTime = timing => {
const now = performance.now();
if (!timing.startTime) timing.startTime = now;
const elapsed = now - timing.startTime;