Files
freeCodeCamp/curriculum/challenges/chinese/03-front-end-libraries/react/create-a-complex-jsx-element.chinese.md
Oliver Eyton-Williams 61460c8601 fix: insert blank line after ```
search and replace ```\n< with ```\n\n< to ensure there's an empty line
before closing tags
2020-08-16 04:45:20 +05:30

2.6 KiB
Raw Blame History

id, title, challengeType, isRequired, videoUrl, localeTitle
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');
  - text: <code>div</code>应该包含一个<code>p</code>标签作为第二个元素。
    testString: assert(JSX.props.children[0].type === 'h1');
  - text: <code>div</code>应包含<code>ul</code>标记作为第三个元素。
    testString: assert(JSX.props.children[1].type === 'p');
  - text: <code>div</code>应包含一个<code>h1</code>标记作为第一个元素。
    testString: assert(JSX.props.children[2].type === 'ul');
  - text: <code>ul</code>应该包含三个<code>li</code>元素。
    testString: assert(JSX.props.children.filter(ele => ele.type === 'ul')[0].props.children.filter(ele => ele.type === 'li').length === 3);

Challenge Seed

// write your code here

After Test

console.info('after the test');

Solution

// solution required

/section>