Skip to content

Commit 3b6f13f

Browse files
joaoassisbJoão Vitor
and
João Vitor
authored
feat(forms): include an afterChange callback to useFormControl (#33)
Co-authored-by: João Vitor <[email protected]>
1 parent a808b4e commit 3b6f13f

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/forms/helpers/useFormControl.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
import { useContext, useCallback } from 'react';
2-
import { isEmptyStringLike, isBoolean } from 'js-var-type';
2+
import { isEmptyStringLike, isBoolean, isFunction } from 'js-var-type';
33
import { FormContext } from './form-helpers';
44
import { toDatetimeLocal, fromDatetimeLocal } from '../../utils/formatters';
55

6-
export function useFormControl(name, type) {
6+
export function useFormControl(name, type, hooks = { afterChange: () => {} }) {
77
const formState = useContext(FormContext);
88

99
function setValue(value) {
1010
formState.update(name, value);
11+
12+
if (isFunction(hooks.afterChange)) {
13+
hooks.afterChange(value);
14+
}
1115
}
1216

1317
const register = useCallback(

0 commit comments

Comments
 (0)