--- id: 5a24c314108439a4d403616c title: Override Default Props challengeType: 6 isRequired: false videoUrl: '' localeTitle: 覆盖默认道具 --- ## Description
设置默认道具的能力是React中的一个有用功能。覆盖默认道具的方法是显式设置组件的prop值。
## Instructions
ShoppingCart组件现在呈现子组件Items 。此Items组件的默认prop quantity设置为整数0 。通过为quantity传递值10来覆盖默认支柱。 注意:请记住,向组件添加prop的语法与添加HTML属性的方式类似。但是,由于quantity的值是一个整数,因此它不会引用引号,但应该用大括号括起来。例如, {100} 。此语法告诉JSX将大括号内的值直接解释为JavaScript。
## Tests
```yml tests: - text: ShoppingCart应该呈现组件。 testString: 'assert((function() { const mockedComponent = Enzyme.mount(React.createElement(ShoppingCart)); return mockedComponent.find("ShoppingCart").length === 1; })(), "The component ShoppingCart should render.");' - text: 该组件Items应该呈现。 testString: 'assert((function() { const mockedComponent = Enzyme.mount(React.createElement(ShoppingCart)); return mockedComponent.find("Items").length === 1; })(), "The component Items should render.");' - text: 'Items组件应具有从ShoppingCart组件传递的{ quantity: 10 }的prop。' testString: 'getUserInput => assert((function() { const mockedComponent = Enzyme.mount(React.createElement(ShoppingCart)); return mockedComponent.find("Items").props().quantity == 10 && getUserInput("index").replace(/ /g,"").includes(""); })(), "The Items component should have a prop of { quantity: 10 } passed from the ShoppingCart component.");' ```
## Challenge Seed
```jsx const Items = (props) => { return

Current Quantity of Items in Cart: {props.quantity}

} Items.defaultProps = { quantity: 0 } class ShoppingCart extends React.Component { constructor(props) { super(props); } render() { { /* change code below this line */ } return { /* change code above this line */ } } }; ```
### After Test
```js console.info('after the test'); ```
## Solution
```js // solution required ```