2.1 KiB
2.1 KiB
id | title | challengeType | isRequired | videoUrl | localeTitle |
---|---|---|---|---|---|
5a24c314108439a4d403616b | Use Default Props | 6 | false | 使用默认道具 |
Description
MyComponent.defaultProps = { location: 'San Francisco' }
,则您已定义了设置为San Francisco
字符串的位置道具,除非您另行指定。如果道具未定义,则React会指定默认道具,但如果您将null
作为道具的值传递,则它将保持为null
。 Instructions
ShoppingCart
组件。在此组件上定义默认道具,指定值为0
的道具items
。 Tests
tests:
- text: <code>ShoppingCart</code>组件应该呈现。
testString: 'assert((function() { const mockedComponent = Enzyme.mount(React.createElement(ShoppingCart)); return mockedComponent.find("ShoppingCart").length === 1; })(), "The <code>ShoppingCart</code> component should render.");'
- text: '<code>ShoppingCart</code>组件应具有<code>{ items: 0 }</code>的默认支柱。'
testString: 'assert((function() { const mockedComponent = Enzyme.mount(React.createElement(ShoppingCart)); mockedComponent.setProps({items: undefined}); return mockedComponent.find("ShoppingCart").props().items === 0; })(), "The <code>ShoppingCart</code> component should have a default prop of <code>{ items: 0 }</code>.");'
Challenge Seed
const ShoppingCart = (props) => {
return (
<div>
<h1>Shopping Cart Component</h1>
</div>
)
};
// change code below this line
After Test
console.info('after the test');
Solution
// solution required