I created this little function to find children of a specific type.
I'd like to be able to select children via property like jQuery, [name="example"]. Is there any way to strip the string selector functionality from jQuery to create an object map to feed to something like lodash's _.find?
I realize this is a fake solution for selecting / finding / filtering an array but I think it can be really useful. I also know that it won't find deep children, it would just deal with direct root children.
Does this exist within react already?
function containsElement (element, children) {
var result = []
element = _.flatten([element])
if (React.isValidElement(children) && !_.isArray(children)) {
var contains = _.contains(element, children.type)
if (contains) return children
return false
} else if (!React.isValidElement(children) && !_.isArray(children)) {
return false
}
children.forEach(function (child) {
var isElm = React.isValidElement(child)
var contains = _.contains(element, child.type)
if (isElm && contains) {
result.push(child)
}
})
if (!result.length) return false
return result
}
Here's a simple version of what I want that only supports element type.
Ideally I can do this and it would get all
divswith thenamepropset tohello.Here's full example, (jsbin).