Created
April 6, 2017 19:04
-
-
Save Swivelgames/c068e513b5cce4e5cde0c315da9bd11f to your computer and use it in GitHub Desktop.
React Utility: mapChildrenToObject
This file contains hidden or 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
const mapChildrenToObject = (children) => ( | |
children.reduce((v, cV) => { | |
let { name } = cV.type; | |
if (!name) return v; | |
if (name === 'Connect') { | |
name = cV.type.displayName.replace(/Connect\((\w+)\)/g, '$1'); | |
} | |
return Object.assign({}, v, | |
v[cV.type.name] ? { | |
[cV.type.name]: [].concat(v[cV.type.name], cV) | |
} : { | |
[cV.type.name]: cV | |
} | |
); | |
}, {}) | |
); | |
export default mapChildrenToObject; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment