This repository has been archived on 2024-11-11. You can view files and clone it, but cannot push or open issues or pull requests.
Go to file
2020-10-29 16:47:15 +01:00
.github ci: update node.js to cache dependencies 2020-10-29 16:47:15 +01:00
example fix: polyfill-object.fromentries 2020-10-26 02:56:36 +01:00
src fix: polyfill-object.fromentries 2020-10-26 02:56:36 +01:00
.editorconfig 🎉 Initial commit 2020-08-04 16:22:31 +02:00
.eslintignore 🎉 Initial commit 2020-08-04 16:22:31 +02:00
.eslintrc fix: polyfill-object.fromentries 2020-10-26 02:56:36 +01:00
.gitignore 🎉 Initial commit 2020-08-04 16:22:31 +02:00
.prettierrc 🎉 Initial commit 2020-08-04 16:22:31 +02:00
commitlint.config.js chore: configurations and update deps 2020-10-03 19:07:09 +02:00
LICENSE chore: configurations and update deps 2020-10-03 19:07:09 +02:00
package-lock.json fix: polyfill-object.fromentries 2020-10-26 02:56:36 +01:00
package.json ci: node.js >= 12 2020-10-26 03:14:42 +01:00
README.md chore: configurations and update deps 2020-10-03 19:07:09 +02:00
tsconfig.json chore: configurations and update deps 2020-10-03 19:07:09 +02:00
tsconfig.test.json 🎉 Initial commit 2020-08-04 16:22:31 +02:00

react-component-form

Manage React Forms with ease.

JavaScript Style Guide Conventional Commits Licence MIT npm version Node.js CI

📜 About

react-component-form is a lightweight form component for React.js, it allows you to get the inputs values without state thanks to onChange or onSubmit props.

Demo : https://divlo.github.io/react-component-form/.

This project was bootstrapped with create-react-library.

💾 Install

npm install --save react-component-form

⚙️ Usage

import React from 'react'
import Form, { HandleForm } from 'react-component-form'

const Example = () => {
  const handleSubmit: HandleForm = (formData, formElement) => {
    console.log(formData) // { inputName: 'value of the input' }
    formElement.reset()
  }

  return (
    <Form onSubmit={handleSubmit}>
      <input type='text' name='inputName' />
      <button type='submit'>Submit</button>
    </Form>
  )
}

Note : The example use TypeScript, but obviously you can use JavaScript. Be aware that HandleForm is the type definition for the onChange and onSubmit props.

Basically you have access to the same props of the HTML form tag in React, but the onSubmit and the onChange props are differents.

Instead to get the event param you get formData and formElement params :

  • formData: It's an object where the keys are the name of your inputs and the current value. Behind the scene, it uses the FormData constructor.
  • formElement: It's the actual HTML form element in the DOM so for example you can access the .reset() method on a HTMLFormElement.

📄 License

MIT