Store
Store is a core functionality in Ts Nano Form designed to store a value that can be validated and observed in real time. This feature helps to manage form values and errors that needs to be updated and accessed globally.
import NanoForm from "ts-nano-form";
type FormUserType = {
document: string;
};
const TsNanoForm = NanoForm();
const FormUser = TsNanoForm.createForm<FormUserType>({
name: "form-user",
initialValues: {
document: "12345",
},
});
const { subscribeValue, setValue } = FormUser.field("document");
subscribeValue((value: string, prevValue: string) =>
console.log(value, prevValue)
);
setValue("67890");
// 67890 12345