From 7b00afa4f41ce6953dc136d5138025ac1b16d08e Mon Sep 17 00:00:00 2001 From: JaydeeSaleCBOS <64138738+JaydeeSaleCBOS@users.noreply.github.com> Date: Wed, 10 Jun 2020 11:38:36 +0200 Subject: [PATCH] Handle undefined values in state handling of undefined values in state, so if the form doesn't exist it would create it and add it to store rather than fail over. i.e state = { sampleForm: undefined } usage: ...mapFields(['sampleForm.name']) this would fail, now succeeds and creates the name prop with undefined rather than failing --- src/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/index.js b/src/index.js index 90a88331..4191b3d3 100644 --- a/src/index.js +++ b/src/index.js @@ -23,7 +23,7 @@ function normalizeNamespace(fn) { } export function getField(state) { - return path => path.split(/[.[\]]+/).reduce((prev, key) => prev[key], state); + return path => path.split(/[.[\]]+/).reduce((prev, key) => (prev ? prev[key] : undefined), state); } export function updateField(state, { path, value }) {