Skip to content

Instantly share code, notes, and snippets.

View jonathangiardino's full-sized avatar

Jonathan Giardino jonathangiardino

View GitHub Profile
@jonathangiardino
jonathangiardino / useForm.js
Last active August 31, 2021 14:21
Form handling hook for React
import { useState } from 'react';
const useForm = (defaults) => {
const [values, setValues] = useState(defaults);
const updateValue = (e) => {
// check if its a number and convert
let { value, type, name } = e.target;
if (type === 'number') {
value = parseInt(value);