Ecosyste.ms: Awesome

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

Awesome Lists | Featured Topics | Projects

https://github.com/singhtal/formtojson


https://github.com/singhtal/formtojson

Last synced: 3 months ago
JSON representation

Awesome Lists containing this project

README

        

Lighest Form to JSON data plugin ⚡⚡
## Usage

Install the plugin

```Bash
npm i react-form2json
```

### Using plugin in react code

```javascript
import formtojson from "react-form2json";
```

#### Pass event as a parameter
formtojson takes submit event as a paramter, event is e in this case.

```javascript
const data = formtojson(e);
console.log(data);
```

#### React Example

```javascript
import React, { useState } from "react";
import formtojson from "react-form2json";
function Myform() {
const [name, setName] = useState("Talvinder");
const [age, setAge] = useState("20");
const handleClick = (e) => {
const data = formtojson(e);
console.log(data);
};
const handleName = (e) => {
setName(e.target.value);
};
const handleAge = (e) => {
setAge(e.target.value);
};
return (


handleClick(e)}>
handleName(e)}
/>
handleAge(e)}
/>
Submit


);
}
export default Myform;

```

On Form Submit the output will be -

```bash
{"name":"Talvinder","age":"20"}
```