Currently creating a form in Reason React is currently a bit verbose for the simple cases when you just want to follow that 80% use case. I’ve created a small library to solve my own problem with this for a production Reason web app. I’ve tried to make it flexible enough so it’s simple by default but extensible when you need to handle different use cases (like custom validations, custom error text, translating text, etc…)
I would really like to hear your honest feedback on how I can make the API better before I finish it and release it. Bear in mind that the documentation that I wrote out tonight is a bit rough.
I would also love any feedback on the programming in general and if I can improve that, as I’m fairly new to Reason and haven’t used OCaml before.
Example
open SimpleForm;
let component = ReasonReact.reducerComponent("SignupForm");
let formSchema: SimpleForm.schemaList = [
{name: "username", label: "Username", validations: [MinLen(2), MaxLen(20)]},
{name: "email", label: "email", validations: [Email]},
{name: "age", label: "Age", validations: [Regex(myRegex, "Invalid Age")]},
];
let handleSubmit = (formState) =>
Js.log(formState.inputValues);
let make = _children => {
...component,
render: _self =>
<Form schema=formSchema onSubmit=handleSubmit>
<TextInput name="firstName" />
<TextInput name="lastName" beforeUpdate=String.lowercase />
<IntInput name="age" />
<Submit text="Sign Up" />
</Form>,
};
More docs and CRA example app here: