Skip to content

Instantly share code, notes, and snippets.

View soker90's full-sized avatar
🏊
Building...

Eduardo Parra soker90

🏊
Building...
View GitHub Profile
@soker90
soker90 / await.tsx
Created September 27, 2023 18:12
Await component
import type { JSX } from 'react';
interface AwaitProps<T> {
promise: Promise<T>;
children: (result: T) => JSX.Element;
}
const Await = async <T,>({ promise, children }: AwaitProps<T>) => {
const result = await promise;
@soker90
soker90 / conditional.js
Created June 28, 2021 09:05
functional conditional
export const matched = param => ({
on: () => matched(param),
otherwise: () => param,
});
export const matchRedirect = param => ({
on: (pred, fn) => (pred(param) ? matched(fn(param)) : matchRedirect(param)),
otherwise: fn => fn(param),
});
@soker90
soker90 / App.tsx
Last active June 21, 2022 07:11
Debounce hook
import { useEffect } from "react";
import { useDebounce } from "hooks";
const App = () => {
const debounce = useDebounce();
useEffect(() => {
debounce(() => {
console.log('Hello world')
@soker90
soker90 / useIsMountedRef.js
Created August 30, 2020 18:32
Hook for useEffect dependecy
import { useRef, useEffect } from 'react';
const useIsMountedRef = () => {
const isMounted = useRef(true);
useEffect(() => () => {
isMounted.current = false;
}, []);
return isMounted;
@soker90
soker90 / create-reducer.js
Last active June 24, 2020 21:22
Create reducer with default setPayload
import { setPayload } from './setPayload';
/**
* Busca si el handler dado es una funcion,
* si lo es devuelve la función, si no lo es
* devuelve una función setPayload por defecto
* @param {function | string} actionHandler
* @returns {function}
* @private
*/