Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/chenxsan/formay

A dead simple form library for Preact.
https://github.com/chenxsan/formay

form preact

Last synced: 27 days ago
JSON representation

A dead simple form library for Preact.

Awesome Lists containing this project

README

        

# Formay

A dead simple form library for Preact with only 1.4kB (gzipped).

## Installation

```sh
npm install formay
```

## Example

[Example on codesandbox](https://codesandbox.io/s/q3xl2l1r09).

```js
/** @jsx h */
import { h, Component } from "preact";
import Formay from "formay";
export default class SignUpForm extends Component {
render() {
return (
{
let errors = {};
const { nickname, email } = state;
if (nickname.trim() === "") {
errors["nickname"] = "can't be blank";
}
if (email.trim() === "") {
errors["email"] = "can't be blank";
}
return errors;
}}
onSubmit={(values, setState) => {
window.alert(JSON.stringify(values));
// we can call setState from form here.
}}
render={({ state, errors, updateValue, onSubmit }) => (


{errors["nickname"] ? {errors["nickname"]} : undefined}

{errors["email"] ? {errors["email"]} : undefined}


)}
/>
);
}
}
```
## TODO

1. [ ] Add test