@hiogopariz/react-object-forms
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published

react-object-forms

NPM JavaScript Style Guide

Install

npm install --save @hiogopariz/react-object-forms

or

yarn add @hiogopariz/react-object-forms

Usage

Create your form inputs once, use it everywhere

import React from 'react';

import { createFormTemplate } from 'react-object-forms';

function CustomInput({value, onChange, ...props}) {
 return <input value={value} onChange={(e) => onChange(e.target.value)} {...props} />;
}

function CustomFormContainer({ onSubmit, fields }) {
 return (
  <form onSubmit={onSubmit}>
   {fields}
   <input type='submit' />
  </form>
 );
}

const myFormTemplate = createFormTemplate({
 components: [['input', CustomInput]],
 wrapper: CustomFormContainer,
});

const MyCustomForm = myFormTemplate.generate({
 name: 'input',
 email: {
  component: 'input',
  props: {
   type: 'email',
  },
 },
});

function App() {
 const onSubmit = (data) => console.log(data);
 const defaultValues = {
  name: '',
  email: '',
 };

 return <MyCustomForm onSubmit={onSubmit} defaultValues={defaultValues} />;
}

License

MIT © HiogoPariz

Package Sidebar

Install

npm i @hiogopariz/react-object-forms

Weekly Downloads

0

Version

1.0.0

License

MIT

Unpacked Size

65.7 kB

Total Files

24

Last publish

Collaborators

  • hiogopariz