react-formwork

1.5.3 • Public • Published

React-Formwork

A ReactJS higher order component (HoC) to generate an HTML form from a Javascript object.

Using:

  • Install from npm:

npm install --save react-formwork

  • Import:

import Formwork from 'react-formwork'

  • Wrap a form component with the Formwork HoC:
class MyForm extends Component {
    render() {
        const { fields, submit, data } = this.props.formwork;
        return (
            <form>
                {fields}
                {submit}
                <pre>
                    {JSON.stringify(data, null, 2)}
                </pre>
            </form>
        )
    }
}

const model = {
    name: 'David',
    email: 'a@b.c',
    jobTitle: 'Developer'
};

export default Formwork(MyForm, {
    fields: model,
    data: model
});

In the example above we pass our JS object model to the Formwork HoC. We pull the generated HTML form fields, the submit button and our bound data object from props.formwork

For additional documentation visit the: GitHub repo

Readme

Keywords

Package Sidebar

Install

npm i react-formwork

Weekly Downloads

2

Version

1.5.3

License

ISC

Unpacked Size

9.99 kB

Total Files

3

Last publish

Collaborators

  • davesnotes