-
-
Save 6ewis/30339f06c20544fa3132b256aa8830dc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
updateFormData(object) { | |
//initial state of address container | |
//addressContainer: { | |
// #1RegisteredAddress: { | |
// line_2: '2', | |
// line_3, '3' | |
// } | |
// #2DividendAddres: { | |
// Line2: "2", | |
// Line3: "3" | |
// } | |
//} | |
//we expect an object with a single key and value | |
const firstKey = (anyObject) => R.keys(anyObject)[0]; | |
const rootObjectKey = firstKey(object); //#1RegisteredAddress | |
const rootObjectValue = object[rootObjectKey]; //{Line_1: 1} | |
//we also expect the nestedObject to have a single key and value | |
const nestedObjectKey = firstKey(rootObjectValue); //Line_1 | |
const nestedObjectValue = R.prop(nestedObjectKey, rootObjectValue); //1 | |
const updateNestedProp = | |
(acc, next) => R.assocPath([rootObjectKey, nestedObjectKey], nestedObjectValue, next); | |
const updatedState = | |
R.reduce(updateNestedProp, {}, [this.state.addressContainer]); | |
//final state of address container | |
//addressContainer: { | |
// #1RegisteredAddress: { | |
// Line_1: "1", | |
// line_2: '2', | |
// line_3, '3' | |
// } | |
// #2DividendAddres: { | |
// Line2: "2", | |
// Line3: "3" | |
// } | |
//} | |
this.setState({addressContainer: updatedState}); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment