Skip to content

Instantly share code, notes, and snippets.

View jerickgm89's full-sized avatar
:electron:
Focusing

JErickDev jerickgm89

:electron:
Focusing
  • Perú
  • 14:47 (UTC -05:00)
View GitHub Profile
@jerickgm89
jerickgm89 / useTodo.js
Created February 5, 2024 23:04
Hook useTodo
import { useEffect, useReducer } from "react";
import { todoReducer } from "../08-useReducer/todoReducer";
const initialState = []
const init = () => {
return JSON.parse(localStorage.getItem('todos')) || [];
}
export const useTodo = () => {
@jerickgm89
jerickgm89 / useForm.js
Created February 5, 2024 23:03
Hook useForm
import { useState } from 'react';
export const useForm = ( initialForm = {}) => {
const [formState, setFormState] = useState( initialForm )
const onInputChange = ({ target}) => {
const { name, value } = target;
setFormState({
...formState,
@jerickgm89
jerickgm89 / useFetch.js
Created February 5, 2024 23:03
Hook useFetch
import { useEffect, useState } from "react"
export const useFetch = ( url ) => {
const [state, setState] = useState({
data: null,
loading: true,
hasError: null
})
@jerickgm89
jerickgm89 / useCounter.js
Last active February 5, 2024 23:04
Hooks JErickDev
import { useState } from "react"
export const useCounter = (initialValue = 10) => {
const [ counter, setCounter ] = useState(initialValue)
const increment = ( value = 1 ) => {
setCounter( counter + value )
}