@britannica/react-hooks
Advanced tools
Comparing version 0.2.7 to 0.2.8
import { bindActionCreators } from 'redux'; | ||
import { useDispatch } from 'react-redux'; | ||
import { useMemo, useState, useEffect } from 'react'; | ||
function useActions(actions, deps, dispatch) { | ||
// const dispatch = useDispatch(); | ||
function useActions(actions, deps) { | ||
const dispatch = useDispatch(); | ||
return useMemo(() => { | ||
@@ -143,2 +144,34 @@ if (Array.isArray(actions)) { | ||
export { useActions, useForm }; | ||
/** | ||
* Map a `yup` ValidationError object to individual form fields | ||
* e.g. | ||
* { | ||
* field1: [ | ||
* 'Error message 1', | ||
* 'Error message 2', | ||
* ], | ||
* field2: [ | ||
* 'Error message 3', | ||
* ], | ||
* } | ||
* | ||
* @param {ValidationError} validationError | ||
* @returns {object} | ||
*/ | ||
const mapValidationErrorToFormFields = validationError => { | ||
if (!validationError.inner) { | ||
return {}; | ||
} | ||
const errors = {}; | ||
validationError.inner.forEach(error => { | ||
if (!errors[error.params.path]) { | ||
errors[error.params.path] = []; | ||
} | ||
errors[error.params.path].push(error.message); | ||
}); | ||
return errors; | ||
}; | ||
export { mapValidationErrorToFormFields, useActions, useForm }; |
{ | ||
"name": "@britannica/react-hooks", | ||
"version": "0.2.7", | ||
"version": "0.2.8", | ||
"description": "", | ||
@@ -40,3 +40,3 @@ "main": "dist/bundle.js", | ||
"redux": "~4.0.1", | ||
"react-redux": "~7.0.3" | ||
"react-redux": "^7.1.0-alpha.4" | ||
}, | ||
@@ -43,0 +43,0 @@ "browserslist": [ |
5307
148