diff --git a/src/makeReactNativeField.js b/src/makeReactNativeField.js index b3755ba..85735e1 100644 --- a/src/makeReactNativeField.js +++ b/src/makeReactNativeField.js @@ -1,11 +1,12 @@ import { compose, mapProps } from "recompose"; +import _ from 'lodash'; + import withFormik from "./withFormik"; -import { selectValue } from './utils'; const makeReactNativeField = compose( withFormik, mapProps(({ formik: { setFieldValue, setFieldTouched, values }, name, ...props }) => ({ - value: selectValue(values, name), + value: _.get(values, name), ...props, name, onChangeText: text => { diff --git a/src/utils.js b/src/utils.js deleted file mode 100644 index 2e8bb6c..0000000 --- a/src/utils.js +++ /dev/null @@ -1,13 +0,0 @@ -export const selectValue = (values, name) => { - if (!name.includes('.')) { - return values[name]; - } else { - const nestedKeys = name.split('.'); - selectedValue = values[nestedKeys[0]]; - for (let i = 1; i < nestedKeys.length; i += 1) { - selectedValue = selectedValue[nestedKeys[i]]; - } - - return selectedValue; - } -}; \ No newline at end of file diff --git a/src/withError.js b/src/withError.js index 22e4bb9..b4f0373 100644 --- a/src/withError.js +++ b/src/withError.js @@ -1,11 +1,12 @@ import { compose, mapProps } from "recompose"; +import _ from 'lodash'; + import withFormik from "./withFormik"; -import { selectValue } from './utils'; const withError = compose( withFormik, mapProps(({ formik: { errors }, name, ...props }) => ({ - error: selectValue(errors, name), + error: _.get(errors, name), ...props, name })) diff --git a/src/withTouched.js b/src/withTouched.js index 7a3d938..5ca4931 100644 --- a/src/withTouched.js +++ b/src/withTouched.js @@ -1,11 +1,12 @@ import { compose, mapProps } from "recompose"; +import _ from 'lodash'; + import withFormik from "./withFormik"; -import { selectValue } from './utils'; const withError = compose( withFormik, mapProps(({ formik: { touched }, name, ...props }) => ({ - touched: selectValue(touched, name), + touched: _.get(touched, name), ...props, name }))