mirror of
https://github.com/yewstack/yew.git
synced 2025-12-08 21:26:25 +00:00
* Reorganize docs * delete wasm-build-tools.mdx * more small updates * i hate versioned docs * seems like I've got the traits of the certain owl who guards over the civilization when it comes to `;` * just work please * Update website/docs/concepts/components/lifecycle.mdx Co-authored-by: Julius Lungys <32368314+voidpumpkin@users.noreply.github.com> * little things * post merge fixes * npm update Co-authored-by: Julius Lungys <32368314+voidpumpkin@users.noreply.github.com>
75 lines
1.0 KiB
Plaintext
75 lines
1.0 KiB
Plaintext
---
|
|
title: "Conditional rendering"
|
|
description: "Rendering nodes conditionally in html!"
|
|
---
|
|
|
|
import Tabs from '@theme/Tabs';
|
|
import TabItem from '@theme/TabItem';
|
|
|
|
|
|
## If blocks
|
|
|
|
To conditionally render some markup, we wrap it in an `if` block:
|
|
|
|
<Tabs>
|
|
<TabItem value="if" label="if">
|
|
|
|
```rust
|
|
use yew::html;
|
|
|
|
html! {
|
|
if true {
|
|
<p>{ "True case" }</p>
|
|
}
|
|
};
|
|
```
|
|
|
|
</TabItem>
|
|
<TabItem value="if - else" label="if - else">
|
|
|
|
```rust
|
|
use yew::html;
|
|
let some_condition = true;
|
|
|
|
html! {
|
|
if false {
|
|
<p>{ "True case" }</p>
|
|
} else {
|
|
<p>{ "False case" }</p>
|
|
}
|
|
};
|
|
```
|
|
|
|
</TabItem>
|
|
<TabItem value="if let" label="if let">
|
|
|
|
```rust
|
|
use yew::html;
|
|
let some_text = Some("text");
|
|
|
|
html! {
|
|
if let Some(text) = some_text {
|
|
<p>{ text }</p>
|
|
}
|
|
};
|
|
```
|
|
|
|
</TabItem>
|
|
<TabItem value="if let else" label="if let else">
|
|
|
|
```rust
|
|
use yew::html;
|
|
let some_text = Some("text");
|
|
|
|
html! {
|
|
if let Some(text) = some_text {
|
|
<p>{ text }</p>
|
|
} else {
|
|
<p>{ "False case" }</p>
|
|
}
|
|
};
|
|
```
|
|
|
|
</TabItem>
|
|
</Tabs>
|