import {useReducer} from 'react' const errorReducer = (errors, action) => { switch (action.type) { case 'set_errors': const newErrors = {} for(const field of action.errors) newErrors[field.param] = field.msg return newErrors case 'clear_error': console.log('clear_error', action) return { ...errors, [action.field]: undefined } default: return errors } } export default function useErrorReducer(initialState = {}){ return useReducer( errorReducer ) }