Skip to content

Instantly share code, notes, and snippets.

@mattiaz9
mattiaz9 / blurhashDataURL.ts
Last active July 19, 2024 05:10
Convert blurhash to a base64 DataURL string (no canvas or node-canvas)
import { decode } from "blurhash"
export function blurHashToDataURL(hash: string | undefined): string | undefined {
if (!hash) return undefined
const pixels = decode(hash, 32, 32)
const dataURL = parsePixels(pixels, 32, 32)
return dataURL
}
import { useState, useRef, useCallback, useEffect } from 'react';
function useInfiniteScroll() {
const [page, setPage] = useState(1);
const loadMoreRef = useRef(null);
const handleObserver = useCallback((entries) => {
const [target] = entries;
if (target.isIntersecting) {
setPage((prev) => prev + 1);