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.
				
			
		
		
		
			
				
					
						
					
					3a876bd6c4e3c81d56ab569be8d07961d37ce5cd
				
			
			
		
	react-component-form
Manage React Forms with ease.
📜 About
react-component-form is a lightweight form component for React.js, it allows you to get the inputs values without state with onChange or onSubmit props.
You can test the library with this link : https://divlo.github.io/react-component-form/.
💾 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>
  )
}
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 params you get formData and formElement :
- formData: It's an object where the keys are the name of your inputs and the current value. Behind the scene, it uses the- FormDataconstructor.
- formElement: It's the actual HTML form element in the DOM so for example you can access the- .reset()method on a- HTMLFormElement.
📄 License
Description
				
					Languages
				
				
								
								
									TypeScript
								
								94.8%
							
						
							
								
								
									JavaScript
								
								2.8%
							
						
							
								
								
									CSS
								
								2.4%