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-inputs

v2.7.0

Published

Redux actions and reducers for managing and validating forms and inputs

Downloads

968

Readme

redux-inputs

npm version Build Status

redux-inputs works with redux to validate and store values from inputs and forms.

Features

  • Declarative validation
  • Declarative parsing
  • Declarative formatting
  • Async validation
  • Per-input validation
  • Cross-field validation
  • Custom input components
  • Programatic value collection
  • Programatic value initialization
  • Programatic value modification
  • Programatic input reset

Docs

Installation

npm install --save redux-inputs

Single File Example

import React from 'react';
import ReactDOM from 'react-dom';
import { createStore, combineReducers, applyMiddleware } from 'redux';
import { createInputsReducer, connectWithInputs, ReduxInputsWrapper } from 'redux-inputs';
import { Provider } from 'react-redux';
import thunk from 'redux-thunk';

// Define configuration for this form. A single input named 'email' with a default value and a function to determine validity.
const inputsConfig = {
    email: {
        defaultValue: '[email protected]',
        validator: (value) => typeof value === 'string' && value.indexOf('@') >= 0
    }
};

// Create redux store with a reducer created with the createInputsReducer function.
const reducer = combineReducers({
    inputs: createInputsReducer(inputsConfig)
});
const store = createStore(reducer, applyMiddleware(thunk));

// Define our own Field component, and wrap it in a ReduxInputsWrapper to easily create a compatible input component.
// Integration with other ui component libraries, such as material-ui, would be done here.
const Field = ({id, value, error, onChange, errorText}) => (
    <div>
        <input name={id} value={value} onChange={(e) => onChange(e.target.value)}/>
        {error ? <p style={{color: 'red'}}>{errorText}</p> : null}
    </div>
);
const ReduxInputsField = ReduxInputsWrapper(Field);

// Use the newly created ReduxInputsField by spreading in reduxInputs.inputProps.email object.
const Form = ({ inputs, reduxInputs }) => (
    <form>
        <ReduxInputsField errorText="Your email must contain an @" {...reduxInputs.inputProps.email}/>
        <h3>Input state</h3>
        <pre>{JSON.stringify(inputs, null, 2)}</pre>
    </form>
);

// Hook the form up to the store with connectWithInputs, a wrapped version of react-redux's connect.
const FormContainer = connectWithInputs(inputsConfig)(s => s)(Form);
ReactDOM.render(<Provider store={store}><FormContainer /></Provider>, document.getElementById('container'));

Contributing

Build

npm i

npm run build

Examples

npm run watch-examples & npm run serve-examples

Tests

npm test