Skip to content

Commit 16905bd

Browse files
committed
fix(forms): fix number input default value to allow 0 to be stored in state
1 parent dd5ce2a commit 16905bd

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/forms/helpers/useFormControl.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export function useFormControl(name, type) {
99
}
1010

1111
return {
12-
getValue: () => encode(formState.getValue(name) || getEmptyValue(type), type),
12+
getValue: () => encode(formState.getValue(name), type),
1313
setValue,
1414
handleOnChange: ({ target }) => {
1515
const value = getTargetValue(target);
@@ -39,6 +39,10 @@ function getEmptyValue(type) {
3939
}
4040

4141
function encode(value, type) {
42+
if (typeof value === 'undefined') {
43+
return getEmptyValue(type);
44+
}
45+
4246
if (type === 'datetime-local') {
4347
return value && value.toISOString().slice(0, 16);
4448
}

0 commit comments

Comments
 (0)