Skip to content

Instantly share code, notes, and snippets.

View SebastianHGonzalez's full-sized avatar

Sebastian Gonzalez SebastianHGonzalez

View GitHub Profile
@SebastianHGonzalez
SebastianHGonzalez / Carousel.jsx
Last active January 3, 2020 19:19
Carousel component with seamless infinite scroll
@SebastianHGonzalez
SebastianHGonzalez / useQueryState.ts
Last active August 22, 2024 19:12
useQueryState - query string synchronized use state hook for next.js
import { useState, useEffect } from "react";
import { useRouter } from "next/router";
type IParam = string;
type IValue = string | string[] | number | number[] | null | undefined;
type IState = { [k: string]: IValue };
type IQuery = IState;
type IRoute = string;
function isEmpty(value: IValue): boolean {
import styled from 'styled-components';
import {
string, bool, oneOf, number,
} from 'prop-types';
function filterObject (f, obj) {
return Object.fromEntries(Object.entries(obj).filter(f));
}
function not (f) {
/**
* Given an async function it will be executed until:
* - maxAttempts has been reached
* - it resolves
* - continueRef turned false
*
* Based off Trey Huffine's article: https://levelup.gitconnected.com/polling-in-javascript-ab2d6378705a
* Adapted to work on react components
*
* @param {Function} fn async function to execute.