--- id: 5a24c314108439a4d403616e title: Access Props Using this.props challengeType: 6 isRequired: false videoUrl: '' localeTitle: 使用this.props访问道具 --- ## Description
最后几个挑战涵盖了将道具传递给子组件的基本方法。但是,如果你传递道具的子组件是ES6类组件,而不是无状态功能组件呢? ES6类组件使用稍微不同的约定来访问props。无论何时在您自己引用类组件时,都使用this关键字。一类组件中访问的道具,你前言您使用与访问它的代码this 。例如,如果ES6类组件具有名为data的prop,则在JSX中编写{this.props.data}
## Instructions
在父组件ResetPassword呈现ReturnTempPassword组件的实例。在这里,给ReturnTempPassword一个tempPassword的prop,并为它tempPassword一个至少8个字符长的字符串的值。在子项ReturnTempPassword ,访问strong标记内的tempPassword prop,以确保用户看到临时密码。
## Tests
```yml tests: - text: ResetPassword组件应返回单个div元素。 testString: 'assert((function() { const mockedComponent = Enzyme.mount(React.createElement(ResetPassword)); return mockedComponent.children().type() === "div"; })(), "The ResetPassword component should return a single div element.");' - text: ResetPassword的第四个子ResetPassword应该是ReturnTempPassword组件。 testString: 'assert((function() { const mockedComponent = Enzyme.mount(React.createElement(ResetPassword)); return mockedComponent.children().childAt(3).name() === "ReturnTempPassword"; })(), "The fourth child of ResetPassword should be the ReturnTempPassword component.");' - text: ReturnTempPassword组件应该有一个名为tempPassword的prop。 testString: 'assert((function() { const mockedComponent = Enzyme.mount(React.createElement(ResetPassword)); return mockedComponent.find("ReturnTempPassword").props().tempPassword; })(), "The ReturnTempPassword component should have a prop called tempPassword.");' - text: ReturnTempPasswordtempPassword道具应该等于至少8字符的字符串。 testString: 'assert((function() { const mockedComponent = Enzyme.mount(React.createElement(ResetPassword)); const temp = mockedComponent.find("ReturnTempPassword").props().tempPassword; return typeof temp === "string" && temp.length >= 8; })(), "The tempPassword prop of ReturnTempPassword should be equal to a string of at least 8 characters.");' - text: ReturnTempPassword组件应显示您在strong标记内作为tempPassword支柱创建的密码。 testString: 'assert((function() { const mockedComponent = Enzyme.mount(React.createElement(ResetPassword)); return mockedComponent.find("strong").text() === mockedComponent.find("ReturnTempPassword").props().tempPassword; })(), "The ReturnTempPassword component should display the password you create as the tempPassword prop within strong tags.");' ```
## Challenge Seed
```jsx class ReturnTempPassword extends React.Component { constructor(props) { super(props); } render() { return (
{ /* change code below this line */ }

Your temporary password is:

{ /* change code above this line */ }
); } }; class ResetPassword extends React.Component { constructor(props) { super(props); } render() { return (

Reset Password

We've generated a new temporary password for you.

Please reset this password from your account settings ASAP.

{ /* change code below this line */ } { /* change code above this line */ }
); } }; ```
### After Test
```js console.info('after the test'); ```
## Solution
```js // solution required ```