UNPKG

react-moment

Version:

React component for the moment date library.

35 lines (33 loc) 819 B
/** * Performs a key comparison between two objects, deleting from the first where * the keys exist in the second * * Can be used to remove unwanted component prop values. For example: * * ```jsx * render() { * const { children, className, ...props } = this.props; * * return ( * <div * {...objectKeyFilter(props, Item.propTypes)} * className={classNames('dp-item', className)} * > * {children} * </div> * ) * } * ``` * * @param {Object} obj1 * @param {Object} obj2 * @returns {*} */ export function objectKeyFilter(obj1, obj2) { const obj2Keys = Object.keys(obj2); const newProps = Object.assign({}, obj1); Object.keys(newProps) .filter(key => obj2Keys.indexOf(key) !== -1) .forEach(key => delete newProps[key]); return newProps; }