tinper-bee-core/js/splitComponent.js

23 lines
679 B
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/**
* 分割要传入父元素和子元素的props
* @param {[object]} props 传入的属性
* @param {[reactElement]} Component 组件
* @return {[array]} 返回数组第一个元素为父元素props对象第二个子元素props对象
*/
export default function splitComponentProps(props, Component) {
const componentPropTypes = Component.propTypes;
const parentProps = {};
const childProps = {};
Object.entries(props).forEach(([propName, propValue]) => {
if (componentPropTypes[propName]) {
parentProps[propName] = propValue;
} else {
childProps[propName] = propValue;
}
});
return [parentProps, childProps];
}