Skip to content

Files

Latest commit

539fde2 · Sep 6, 2016

History

History
47 lines (41 loc) · 1.1 KB

README.md

File metadata and controls

47 lines (41 loc) · 1.1 KB

redux-validation

validate for action property

Installation

npm install --save redux-validation

Usage

  • applyMiddleware
import { createStore, applyMiddleware } from 'redux';
import reducer from './modules/reducer';
import createLogger from 'redux-logger';
import validationMiddleware from 'redux-validation';

export default function() {
  const createStoreWithMiddleware = applyMiddleware(validationMiddleware, createLogger())(createStore);
  return createStoreWithMiddleware(reducer);
}
export const sample = createAction(ACTION_TYPE, (payload) => paylaod, () => ({
  validation: {
    name: [   // input name
     {
        func: (payload) => payload.length > 0, // validation
        msg: 'Name must be Required.', // invalid message
      },
    ],
  },
});
export default handleActions({
  [ACTION_TYPE]: (state, { payload: { data, validation } }) => ({
    ...state,
    name: data,
    validation,
  }),
}, {});