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>
34 lines
1.1 KiB
Plaintext
34 lines
1.1 KiB
Plaintext
---
|
|
title: "Introduction"
|
|
description: "Components in Yew"
|
|
slug: /concepts/components
|
|
---
|
|
|
|
## What are Components?
|
|
|
|
Components are the building blocks of Yew. They manage their own state and can render themselves to the DOM.
|
|
Components are created by implementing the `Component` trait for a type.
|
|
|
|
## Writing Component's markup
|
|
|
|
Yew uses Virtual DOM to render elements to the DOM. The Virtual DOM tree can be constructed by using the
|
|
`html!` macro. `html!` uses syntax which is similar to HTML but is not exactly the same. The rules are also
|
|
much stricter. It also provides super-powers like conditional rendering and rendering of lists using iterators.
|
|
|
|
:::info
|
|
[Learn more about the `html!` macro, how it's used and its syntax](./html)
|
|
:::
|
|
|
|
## Passing data to a component
|
|
|
|
Yew components use *props* to communicate between parent and children. A parent component may pass any data as props to
|
|
its children. Props are similar to HTML attributes but any Rust type can be passed as props.
|
|
|
|
:::info
|
|
[Learn more about the props](./properties)
|
|
:::
|
|
|
|
:::info
|
|
For other than parent/child communication, use [contexts](./contexts)
|
|
:::
|