freeCodeCamp/guide/russian/certifications/front-end-libraries/react/render-conditionally-from-p.../index.md

38 lines
1018 B
Markdown
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

---
title: Render Conditionally from Props
localeTitle: Отказывать условно от реквизита
---
## Отказывать условно от реквизита
Это немного сложно, но легко.
## Решение
Измените `handleClick()` с правильной инструкцией по увеличению.
```react.js
handleClick() {
this.setState({
counter: this.state.counter + 1
});
}
```
В методе `render()` используйте `Math.random()` как указано в описании задачи, и напишите тернарное выражение, чтобы передать `props` в компоненте **Results** .
```react.js
let expression = Math.random() > .5;
{(expression == 1)? <Results fiftyFifty="You win!"/> : <Results fiftyFifty="You lose!"/> }
```
Затем `fiftyFifty` реквизит в компоненте Results.
```react.js
<h1>
{
this.props.fiftyFifty
}
</h1>
```