0.0.6 • Published 7 years ago

@hivelocity/formify v0.0.6

Weekly downloads
1
License
MIT
Repository
-
Last release
7 years ago

Formify

Formify makes an attempt to simplify forms in react and move away from redux-form.

Below is a simple example of how to use Formify

Declaration

const LoginForm = Formify({
    first: '',
    last: '',
    contacts: [{
        first: 'Barney',
        last: 'Calhoun'
    }]
}, ({error, fields}) => (
    <>
        <Error message={error} />
        <TextField {...fields.first} />
        <TextField {...fields.last} type="password" />
        {fields.contacts && fields.contacts.map((contact, index) => <TextField key={index} {...contact.first} />)}
        <FormButton mods={['green', 'padded', 'right']}>Login</FormButton>
    </>
));

Formify is a function that takes an object (fields) and a React Component then returns a Higher Order Component to properly pass the fields to the form.

Easy Implementations

<LoginForm onSubmit={async (fields) => {
    ...do whatever submit logic you need
}}>

If you have an errors go ahead and throw an error in this structure

{
    _error: '',
    fields: {
        first: '',
        last: ''
    }
}

if you throw 'This is an error' on the submit, that string will appear at the top of the form

0.0.6

7 years ago

0.0.5

7 years ago

0.0.4

7 years ago

0.0.3

7 years ago