Open
Description
The use case is when you just need fieldProps but you don't need validation or submit functionality. For example when you don't have a standard form and you just want an easy way to have name, value, onChange, onBlur defined.
So my proposal is to have something like this code below.
This is thought to be used with the useState
so you can pass to fieldProps directly what useState
returns.
const fieldProps = <A, B extends keyof A>(
field: B,
model: [A, (val: A) => void]
): {
name: B;
value: A[B];
onChange: (val: A[B]) => void;
onBlur: () => void;
} => ({
name: field,
value: model[0][field],
onChange: (val) => {
model[1]({
...model[0],
[field]: val,
});
},
onBlur: () => {},
});
Metadata
Metadata
Assignees
Labels
No labels