Files
freeCodeCamp/curriculum/challenges/russian/03-front-end-libraries/react/create-a-stateless-functional-component.russian.md

2.9 KiB
Raw Blame History

id, title, challengeType, isRequired, forumTopicId, localeTitle
id title challengeType isRequired forumTopicId localeTitle
5a24c314108439a4d4036162 Create a Stateless Functional Component 6 false 301392 Создание функционального компонента без учета состояния

Description

Компоненты - это ядро React. Всё в React является компонентом, и здесь вы научитесь, как их создавать.

Существуют два способа создания React компонентов. Первый способ - это использовать JavaScript функцию. Определяя компонент таким образом, вы создаете функциональный компонент без учета состояния. Концепт состояния в приложении будет рассмотрен в дальнейших главах. Сейчас думайте о компоненте без учета состояния, как о компоненте, которая может получать данные и рендерить их, но не управляет или следить за изменениями в данных.

Instructions

The code editor has a function called MyComponent. Complete this function so it returns a single div element which contains some string of text. Note: The text is considered a child of the div element, so you will not be able to use a self-closing tag.

Tests

tests:
  - text: <code>MyComponent</code> should return JSX.
    testString: assert((function() { const mockedComponent = Enzyme.mount(React.createElement(MyComponent)); return mockedComponent.length === 1; })());
  - text: <code>MyComponent</code> should return a <code>div</code> element.
    testString: assert((function() { const mockedComponent = Enzyme.mount(React.createElement(MyComponent)); return mockedComponent.children().type() === 'div' })());
  - text: The <code>div</code> element should contain a string of text.
    testString: assert((function() { const mockedComponent = Enzyme.mount(React.createElement(MyComponent)); return mockedComponent.find('div').text() !== ''; })());

Challenge Seed

const MyComponent = function() {
  // change code below this line



  // change code above this line
}

After Tests

ReactDOM.render(<MyComponent />, document.getElementById('root'))

Solution

const MyComponent = function() {
  // change code below this line
  return (
    <div>
      Demo Solution
    </div>
  );
  // change code above this line
}