3.1 KiB
3.1 KiB
id | title | challengeType | isRequired | videoUrl | localeTitle |
---|---|---|---|---|---|
5a24c314108439a4d4036162 | Create a Stateless Functional Component | 6 | false | 创建无状态功能组件 |
Description
null
的JavaScript函数。需要注意的一件重要事情是,React要求您的函数名称以大写字母开头。这是一个在JSX中分配HTML类的无状态功能组件的示例: //被转换后,<div>将有一个CSS类'customClass'因为JSX组件代表HTML,所以您可以将几个组件放在一起以创建更复杂的HTML页面。这是React提供的组件架构的关键优势之一。它允许您从许多独立的,独立的组件中组合UI。这使得构建和维护复杂的用户界面变得更加容易。
const DemoComponent = function(){
回来(
<div className ='customClass'/>
);
};
Instructions
MyComponent
的函数。完成此函数,以便返回包含一些文本字符串的单个div
元素。 注意:该文本被视为div
元素的子元素,因此您将无法使用自闭合标记。 Tests
tests:
- text: <code>MyComponent</code>应该返回JSX。
testString: 'assert((function() { const mockedComponent = Enzyme.mount(React.createElement(MyComponent)); return mockedComponent.length === 1; })(), "<code>MyComponent</code> should return JSX.");'
- text: <code>MyComponent</code>应该返回一个<code>div</code>元素。
testString: 'assert((function() { const mockedComponent = Enzyme.mount(React.createElement(MyComponent)); return mockedComponent.children().type() === "div" })(), "<code>MyComponent</code> should return a <code>div</code> element.");'
- text: <code>div</code>元素应包含一串文本。
testString: 'assert((function() { const mockedComponent = Enzyme.mount(React.createElement(MyComponent)); return mockedComponent.find("div").text() !== ""; })(), "The <code>div</code> element should contain a string of text.");'
Challenge Seed
const MyComponent = function() {
// change code below this line
// change code above this line
}
After Test
console.info('after the test');
Solution
// solution required