Skip to content

Instantly share code, notes, and snippets.

View hypersnob's full-sized avatar

Oleg Zayarniy hypersnob

  • Berlin, Germany
View GitHub Profile
@hypersnob
hypersnob / useIntersectionObserver.ts
Created January 30, 2024 13:40
Custom React hook that observes a target element and executes a callback when it becomes visible.
import { useEffect, useRef } from "react";
export default function useIntersectionObserver(
el: HTMLElement | null,
callback: (entry: IntersectionObserverEntry) => void,
options: IntersectionObserverInit & {
enabled: boolean;
} = {
root: null,
threshold: 0.4,
@hypersnob
hypersnob / CustomCursor.tsx
Last active February 19, 2024 08:54
Custom cursor wrapper react component using Framer Motion and Tailwind CSS classes.
import { m } from "framer-motion";
import React, { useEffect, useState } from "react";
const CustomCursor: React.FC<{ cursorElement: JSX.Element }> = ({
cursorElement,
}) => {
const [mousePosition, setMousePosition] = useState({ x: -100, y: -100 });
const onMouseMove = (e: MouseEvent) => {
if (!e.target) {