Skip to content
This repository has been archived by the owner on Jul 27, 2022. It is now read-only.

Commit

Permalink
docs: update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
wellyshen committed Nov 21, 2020
1 parent a20770d commit 495f275
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/silly-ligers-develop.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"react-cool-form": patch
---

docs: update readme
69 changes: 66 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,72 @@ React hooks for forms state, validation, and performance.
- [x] Type definition
- [x] Support server-side rendering
- [x] CI/CD
- [x] Reduce bundle size
- [ ] Performance optimizing
- [ ] Documentation
- [ ] Examples
- [ ] Unit testing
- [ ] End to end testing
- [ ] Examples

## Getting Started

To use `react-cool-form`, you must use [email protected] or greater which includes hooks.

You can install this package via [npm](https://www.npmjs.com/package/react-cool-form).

```bash
$ yarn add react-cool-form
# or
$ npm install --save react-cool-form
```

Here's the basic example of how does it works, I'll provide the full documentation soon. If you have any question, feel free to [ask me](https:/wellyshen/react-cool-form/issues/new?template=question.md).

[![Edit useForm - basic](https://codesandbox.io/static/img/play-codesandbox.svg)](https://codesandbox.io/s/react-cool-form-basic-gb0dj?fontsize=14&hidenavigation=1&theme=dark)

```javascript
import { useForm } from "react-cool-form";

const defaultValues = {
name: "",
email: "",
password: "",
};

const App = () => {
const { formRef, getState } = useForm({
// Provide the default values for our form state
defaultValues,
onSubmit: (values, actions) => {
// Triggered when the form is valid
console.log("onSubmit: ", values);
},
onError: (errors, actions) => {
// Triggered when the form is invalid
console.log("onError: ", errors);
},
});

const [errors, touched] = getState(["errors", "touched"]);

return (
<form ref={formRef} noValidate>
<label>Name</label>
{/* Support built-in validation attributes */}
<input name="name" required />
{touched.name && <p>{errors.name}</p>}

<label>Email</label>
<input name="email" type="email" required />
{touched.email && <p>{errors.email}</p>}

<label>Password</label>
<input name="password" required minLength={8} />
{touched.password && <p>{errors.password}</p>}

<input type="reset" />
<input type="submit" />
</form>
);
};
```

Super easy right? The above example is just the tip of the iceberg. `react-cool-form` is a lightweight and powerful form library, you can visit the [type definition](https:/wellyshen/react-cool-form/blob/master/src/types/react-cool-form.d.ts) to understand how it rocks the world 😎.

0 comments on commit 495f275

Please sign in to comment.