Skip to content

Commit

Permalink
fix field.setValue
Browse files Browse the repository at this point in the history
  • Loading branch information
jamiebuilds committed Apr 12, 2019
1 parent 8966ee7 commit a90826d
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions src/react-jeff.ts
Expand Up @@ -166,17 +166,21 @@ export function useField<Val, Err = string>(
})
}

let setValueHandler = (value: Val) => {
valueRef.current = value
setDirty(true)
setValue(value)
setErrors([])
validate()
}

let onChange = (value: Val) => {
if (isReactSyntheticEvent(value)) {
throw new TypeError(
"Expected `field.onChange` to be called with a value, not an event",
)
}
valueRef.current = value
setDirty(true)
setValue(value)
setErrors([])
validate()
setValueHandler(value)
}

let valid = !errors.length
Expand All @@ -185,7 +189,7 @@ export function useField<Val, Err = string>(
value,
errors,
defaultValue,
setValue,
setValue: setValueHandler,
focused,
blurred,
touched,
Expand Down

0 comments on commit a90826d

Please sign in to comment.