Ecosyste.ms: Awesome

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

Awesome Lists | Featured Topics | Projects

https://github.com/leonardomso/slatt

🐍 Another form library for React? Oh, please!
https://github.com/leonardomso/slatt

form form-library formik forms hooks react reactjs

Last synced: 19 days ago
JSON representation

🐍 Another form library for React? Oh, please!

Awesome Lists containing this project

README

        



🐍 Slatt



Another form library to use with React? Oh, please!



Build Status


## Another form library? Oh, please!

I'm just trying to understand how to use custom hooks to deal with forms in React, I was boring so I thought "why not create another form library?". Feel free to contribute.

## Getting Started

To get it started, add `slatt` to your project:

```
npm install --save slatt
```

This library requires `react@^16.8.0` as a peer dependency.

## Usage

```jsx
import React from 'react';
import useSlatt from 'slatt';

const initialValues = {
name: '',
lastName: '',
age: 0,
};

const App = () => {
const validationSchema = Yup.object().shape({
email: Yup.string()
.email('Email is invalid')
.required('Email is required'),
password: Yup.string()
.required('Password is required')
.min(8, 'Password min length is 8'),
});

const {
values,
errors,
touched,
handleChange,
handleBlur,
handleSubmit,
} = useSlatt({
initialValues,
onSubmit: values => console.log({ values }),
validationSchema,
});

return (

🐍 Slatt

Name

{errors.email ?

{errors.email}

: null}

Password

{errors.password ?

{errors.password}

: null}

Submit

);
};

export default App;
```