redux-validation
v0.9.1
Published
redux middleware, validation for action property
Downloads
6
Readme
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);
}
- createAction of
redux-actions
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
},
],
},
});
- handleActions of
redux-actions
export default handleActions({
[ACTION_TYPE]: (state, { payload: { data, validation } }) => ({
...state,
name: data,
validation,
}),
}, {});