Skip to content

Instantly share code, notes, and snippets.

View stivsk's full-sized avatar

Yeison Calle stivsk

  • Medellin - Colombia
View GitHub Profile
@stivsk
stivsk / fibonacciGenerator.js
Last active July 10, 2023 05:11
Fibonacci sequence using Generators
function* fibonacciGenerator() {
const sequence = [0, 1];
yield 0;
yield 1;
while (true) {
let i = sequence.length;
sequence[i] = sequence[i - 1] + sequence[i - 2];
@stivsk
stivsk / useLazySWR.js
Last active July 25, 2022 23:34
Lazy SWR hook for GraphQL requests, compatible with Suspense
import useSWR from 'swr'
import { useState } from 'react'
import request from 'graphql-request'
import _ from 'lodash'
// GraphQL fetcher for SWR hook
export const graphqlFetcher = (query, variables) => request('http://localhost:4000/api/graphql', query, variables)
export const useLazySWR = (query) => {
// We're going to use SWR conditional fetching,
@stivsk
stivsk / useParallax.js
Last active July 1, 2021 01:26
Simple Parallax React Hook
// https://github.com/TheClosure/parallax-tutorial
import { useEffect, useState } from 'react';
const useParallax = (speed = 0.5) => {
const [offsetY, setOffsetY] = useState(0);
const handleScroll = () => setOffsetY(window.pageYOffset);
useEffect(() => {
window.addEventListener('scroll', handleScroll);