freeCodeCamp/curriculum/challenges/chinese/03-front-end-libraries/react/create-a-complex-jsx-elemen...

3.0 KiB
Raw Blame History

id title challengeType isRequired videoUrl localeTitle
5a24bbe0dba28a8d3cbd4c5d Create a Complex JSX Element 6 false 创建一个复杂的JSX元素

Description

最后一个挑战是JSX的一个简单示例但JSX也可以代表更复杂的HTML。关于嵌套JSX的一个重要事项是它必须返回一个元素。这个父元素将包装所有其他级别的嵌套元素。例如编写为没有父包装元素的兄弟姐妹的几个JSX元素将不会转换。这是一个例子 有效的JSX
<DIV>
<p>第一段</ p>
<p>第二段</ p>
<p>第3段</ p>
</ DIV>
JSX无效
<p>第一段</ p>
<p>第二段</ p>
<p>第3段</ p>

Instructions

定义一个新的常量JSX ,它呈现一个按顺序包含以下元素的div :一个h1 ,一个p和一个包含三个li项的无序列表。您可以在每个元素中包含所需的任何文本。 注意:渲染多个这样的元素时,可以将它们全部括在括号中,但并不是严格要求的。另请注意,此挑战使用div标记将所有子元素包装在单个父元素中。如果删除div JSX将不再转换。请记住这一点因为当您在React组件中返回JSX元素时它也将适用。

Tests

tests:
  - text: 常量<code>JSX</code>应该返回一个<code>div</code>元素。
    testString: 'assert(JSX.type === "div", "The constant <code>JSX</code> should return a <code>div</code> element.");'
  - text: <code>div</code>应该包含一个<code>p</code>标签作为第二个元素。
    testString: 'assert(JSX.props.children[1].type === "p", "The <code>div</code> should contain a <code>p</code> tag as the second element.");'
  - text: <code>div</code>应包含<code>ul</code>标记作为第三个元素。
    testString: 'assert(JSX.props.children[2].type === "ul", "The <code>div</code> should contain a <code>ul</code> tag as the third element.");'
  - text: <code>div</code>应包含一个<code>h1</code>标记作为第一个元素。
    testString: 'assert(JSX.props.children[0].type === "h1", "The <code>div</code> should contain an <code>h1</code> tag as the first element.");'
  - text: <code>ul</code>应该包含三个<code>li</code>元素。
    testString: 'assert(JSX.props.children[2].props.children.length === 3, "The <code>ul</code> should contain three <code>li</code> elements.");'

Challenge Seed

// write your code here

After Test

console.info('after the test');

Solution

// solution required