@lynxts/core • Docs
@lynxts/core / fieldOf
fieldOf<
T
>():FieldOf
<T
>
Utility function which helps you create a Field component of an specific struct type. Once you have this, the only type parameters left is the Path<T> of the property and the optional fallback type.
• T extends Struct
FieldOf
<T
>
a Field of the specified struct type
interface User {
age: number;
name: string;
}
const Field = fieldOf<User>();
// Now path may only be "name" or "age"
<Field path="name" fallback={""}>
{({ value, setValue, setTouched, required, error }) => (
<label>
{`Name: ${required ? "*" : ""}`}
<input
type="number"
onChange={e => setValue(e.target.value)}
onBlur={setTouched}
value={value}
/>
{error && <small>{error}</small>}
</label>
)}
</Field>