Skip to content

Instantly share code, notes, and snippets.

View asaumet230's full-sized avatar

Andres Saumet asaumet230

View GitHub Profile
@asaumet230
asaumet230 / useCounter.js
Created March 21, 2022 18:39
Custom Hook UseCounter
import { useState } from "react";
const useCounter = ( initialState = 1 ) => {
const [ counter, setCounter ] = useState( initialState );
const increment = () => {
setCounter( counter + 1 );
}
@asaumet230
asaumet230 / useFetch.js
Last active April 15, 2022 15:22
Custom Hook UseFetch( )
import { useEffect, useRef, useState } from "react";
const useFetch = (url) => {
const isMounted = useRef(true); //mantienes la referencia a la variable.
const [ state, setState ] = useState({
data: null,
loading: true,
@asaumet230
asaumet230 / useForm.js
Last active June 27, 2023 20:41
Custom Hook UseForm( )
import { useState } from "react";
const useForm = ( initialState = {} ) => {
const [ values, setValues ] = useState(initialState);
// Agregar Valores al Formulario:
const handleInputChanges = ( { target } ) => {
setValues({
@asaumet230
asaumet230 / reducer.tsx
Last active April 15, 2022 15:23
Typescript: reducer
import { useReducer, useEffect } from 'react';
interface AuthState {
validando: boolean;
token: null | string;
username: string;
nombre: string;
}
type LoginPayload = {