Informed is a set of components to reduce the work needed to create forms with react.
There are already many different form solution in the react ecosystem. Informed tries to be different by minimizing boilerplate. Informed does not require decorated input elements, either. Typescript definitions are provided for easier form refactoring.
Click here to view a demo.
Form value= preventAction= onChange= div label htmlFor=First Name</label> Field value= debounce= input type="text" placeholder="First Name" disabled= / /Field /div div label htmlFor=Last Name</label> Field value= debounce="onBlur" input type="text" placeholder="Last Name" disabled= / /Field /div div button disabled= className="btn btn-primary" type="submit" submit /button /div/Form
Run examples
See the docs/examples/ directory for examples on how to use this library. To run the examples locally:
npm install
npm start
and open your browser to http://localhost:8000/ (if it doesn't open automatically)
Goals
- Input elements should not be passed as props or wrapped in odd ways.
- There should be full control over look and feel using standard HTML props
- Un-opinionated about how form state is stored
- set the form based on props like with a redux-store sol'n
- or make use of a containing component's state
- Easily integrates custom components (just implement the value/onChange interface)
- Typescript integration
- limit the amount of unnecessary boilerplate needed for controlled elements by automatically adding the needed value/onChange props
Form State Object
Every Form state object implements the BaseForm interface. There are several fields that provide summary info about the form (is<*>).
Finally, each Field is stored as a property where the name of the Field is set to an InputState object.
InputState
Each InputState object has several properties that get updated automatically allowing to easily update the UI in response to events like form errors.
There may be some confusion about the difference between error and honestError. For example, a that is required but initialized with an empty value will immediately have an error. But we wouldn't really indicate an error unless the user had attempted to modify the input and then left its value blank. To avoid having to perform tests against the dirty property, the error property is provided.
Field Usage
should be a direct wrapper around the input element or custom component you want to use. If you need to use a
If you look at the inspected html you can see that does not create a wrapper
Save Form State
The element is configured like a regular controlled component. Implement the 'value' and 'onChange' props and the rest of the form takes care of itself
Form value= onChange= ... /Form
Future Goals and TODOs
- Field does not update when props of a Field is changed manually
- 'validate' prop interface should accept a Promise for async validation
Examples
- classic POST form