npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

redux-form-field

v1.1.0

Published

Easy way to create fields to form for validations, warnings etc...

Downloads

3

Readme

redux-form-field

Easy way to create fields to form for validations, warnings etc... based on redux-form

Introduction

A new architectural approach to creating fields components for redux-form. While you using this library all the logic of redux-form created behind the scenes.

redux-form-field give you a easy way to convert your Container to 'Form Container', and use 'Field Components' inside it.

Form Container - Container that connected to redux-form-field using connectWithReduxForm Field Component - Component that connected to redux-form-field using createField

Quick start

install

$ npm install --save redux-form-field

Add form to your redux. for example:

import { combineReducers } from 'redux';
import { reducer as formReducer } from 'redux-form';

const rootReducer = combineReducers({
    form: formReducer,
});

export default rootReducer;

Convert your component to Field Component with createField

export default createField(MyFieldComponent, {
    nyField_1: PropTypes.string.isRequired,
    nyField_2: PropTypes.string.isRequired
});

Connect your Form Container to redux-form with connectWithReduxForm

export default connectWithReduxForm(MyFormContainer,
    (state) => {
        return {

        }
    },
    {
        myActions
    },
    {
        form : 'MyFormContainerForm',
        fields: ['MyFieldComponent'],
        myValidateFunction
    }
);

Methods

createField

Parameters :
  • component - the component you created
  • propTypes [OPTIONAL] - propTypes that will be combined to the returned component.
Return :

Return redux-form Field component that can be use easly inside forms.

connectWithReduxForm

Parameters :
  • component (container) - the component you want to connect to redux-form.
  • mapStateToProps [OPTIONAL] - states you want to connect to redux.
  • mapDispatchToProps [OPTIONAL] - actions you want to connect to redux.
  • reduxFormConfig - redux-form configuration.
Return :

Return your connected component to redux and redux-form

Usage

createField Example Code

This example show you how to create component and convert it to Field that can be easly to use inside forms to validations, warnings etc... as you can see inside the props that send to your component you can find meta and input data.

  1. meta - include the error/warning message and if field is touched. You can figure out more props on redux-form documentation.
  2. input - here you get all the inputs props. for example : onChange, name etc .. This field make your component like a 'real' input, you can now pass any props that input have and it will auto combine it to the 'real' input inside your component.
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import { createField } from 'redux-form-field';

const component = ({ meta: { touched, error, warning }, input, type, label }) => {

    return (
        <div className="form-group">
            <label>{label}</label>
            <div>
                <input {...input} placeholder={label} type={type} className="form-control"/>
                {error}
            </div>
        </div>
    );

};

export default createField(component, {
    type: PropTypes.string.isRequired,
    label: PropTypes.string.isRequired
});

connectWithReduxForm Example Code

This example show how to use your redux-form-field inside Form Container and how to connect him to redux-form. Input and Textarea are redux-form-field.

import React, { Component } from 'react';
import { connectWithReduxForm } from 'redux-form-field';
import { createPost } from '../../actions/posts/actions_posts';

import { Input, Textarea } from '../../components/core';

class PostsNew extends Component {
    onChg () {
        console.log("Hello redux-form-field");
    }

    render() {
        const { handleSubmit, pristine, reset, submitting }  = this.props;

        return (
            <form onSubmit={handleSubmit(this.props.createPost)} >

                <h3>Create A New Post</h3>

                <Input name="title" type="text" label="Title" onChange={this.onChg} />
                <Input name="categories" type="text" label="Categories" />
                <Textarea name="content" label="Content" onChange={this.onChg} />

                <button type="submit" className="btn btn-primary">Submit</button>

            </form>
        );
    }
}

function validate(values) {
    const errors = {};

    if (!values.title) {
        errors.title = 'Enter a username';
    }

    return errors;
}

export default connectWithReduxForm(PostsNew,
    null,
    {
        createPost
    },
    {
        form : 'PostsNewForm',
        fields: ['title', 'categories', 'content'],
        validate
    }
);