(defaultProps, props)
| 383 | ]; |
| 384 | |
| 385 | export function addDefaultProps(defaultProps, props) { |
| 386 | if (!defaultProps || !props) return props; |
| 387 | |
| 388 | let result = { ...props }; |
| 389 | |
| 390 | Object.keys(defaultProps).forEach((key) => { |
| 391 | if (result[key] === undefined) { |
| 392 | result[key] = defaultProps[key]; |
| 393 | } |
| 394 | if ( |
| 395 | Object.keys(defaultProps[key] || {}).length > 0 && |
| 396 | typeof defaultProps[key] === 'object' |
| 397 | ) { |
| 398 | addDefaultProps(defaultProps[key], result); |
| 399 | } |
| 400 | }); |
| 401 | |
| 402 | return result; |
| 403 | } |