Currently working on developing a custom form type. Here's what I have so far:
function getCustomType<Values extends Record<string, unknown> = Record<string, unknown>>({
defaultValue,
onSubmit
}: {
defaultValue: Values
onSubmit: (values: Values) => void
}): {
value: Values
onSubmit: (value: Values) => void
} {
return {
value: defaultValue,
onSubmit
}
}
const formData = getCustomType({
defaultValue: { dog: 1 },
onSubmit: (data) => {
alert(1)
}
})
Seeking to let the value in the onSubmit
function correspond with the data from the defaultValue
object without needing an additional function call. Is this achievable through a more straightforward approach?