8000 GitHub - r3wt/react-models: decorate your components with convenience functions for wiring up state to your inputs.
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
This repository was archived by the owner on Apr 6, 2020. It is now read-only.

r3wt/react-models

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

react models


easy and convenient models for your react components (inspired by ng-model from angular.js)

api


@withModels - use this decorator on the compents you'd like to use models with. model,checkbox, and radio functions will be added to the component. nested paths have basic support, it may not work with arrays currently but support is planned. you simply call the function(s) in your markup and use the spread operator to apply it to the input components as necessary. should work with both dom inputs and custom components as well.

this.model(str statePath,str inputType) - the statePath of the value, and the inputType, which defaults to 'text' this.checkbox(str statePath,mixed checkedValue) - the statePath of the value, and the checkedValue is the value applied when the checkbox is selected. this.radio(str statePath, mixed optionValue ) - the statepath of the value, and the optionValue is the value applied when the radio is selected.

component api


Several components are provided for you to get started with.

Form - a form component. it can track child inputs and report errors.

example usage:

import React,{Component} from 'react';
import {withModels} from 'react-models';

@withModels class Example extends Component {

    state = {
        user: {
            firstname:'',
            lastname:'',
            password:''
        },
        showPassword: false,
        subscribeToNewsletter:'yes'
    }

    render() {

        return (
            <div>
                <label>First Name</label>
                <input {...this.model('user.firstname')} />

                <label>Last Name</label>
                <input {...this.model('user.lastname')} />
                
                <label>Password</label>
                <input {...this.model('user.password',this.state.showPassword?'text':'password')} />
                <div>
                    <label>Show Password</label>
                    <input {...this.checkbox('showPassword',true)} />
                </div>
                <div>
                    <strong>Do you want to subscribe to our newsletter?</strong>
                    <label>
                    <input {...this.radio('subscribeToNewsletter','yes')} />
                    Yes
                    </label>
                    <label>
                    <input {...this.radio('subscribeToNewsletter','no')} />
                    No
                    </label>
                </div>
            </div>
        )

    }
}

About

decorate your components with convenience functions for wiring up state to your inputs.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published
0