[][src]Crate yew

Yew Framework - API Documentation

Yew is a framework for web-client apps created with a modern Rust-to-Wasm compilation feature. This framework was highly inspired by Elm and React.

Minimal example:

use yew::prelude::*;

struct Model {
    value: i64,
}

enum Msg {
    DoIt,
}

impl Component for Model {
    type Message = Msg;
    type Properties = ();
    fn create(_: Self::Properties, _: ComponentLink<Self>) -> Self {
        Self {
            value: 0,
        }
    }

    fn update(&mut self, msg: Self::Message) -> ShouldRender {
        match msg {
            Msg::DoIt => self.value = self.value + 1
        }
        true
    }

    fn view(&self) -> Html<Self> {
        html! {
            <div>
               <button onclick=|_| Msg::DoIt>{ "+1" }</button>
                <p>{ self.value }</p>
            </div>
        }
    }
}
fn main() {
    yew::initialize();
    App::<Model>::new().mount_to_body();
    yew::run_loop();
}

Re-exports

pub use self::prelude::*;

Modules

agent

This module contains types to support multi-threading in Yew.

app

This module contains the App struct, which is used to bootstrap a component in an isolated scope.

callback

This module contains structs to interact with Scopes.

components

This module contains useful components. At this moment it includes typed Select only.

events

The module that contains all events available in the framework.

format

Utility module to convert data to types and back by specific formats like: JSON, BSON, TOML, YAML, XML.

html

The main module which contents aliases to necessary items to create a template and implement update and view functions. Also this module contains declaration of Component trait which used to create own UI-components.

macros

This module contains macros which implements html! macro and JSX-like templates

prelude

The Yew Prelude

scheduler

This module contains a scheduler.

services

This module is a container of servies to interact with the external resources.

utils

This module contains useful utils to get information about the current document.

virtual_dom

This module contains the implementation of reactive virtual dom concept.

Macros

html

This macro implements JSX-like templates.

Functions

initialize

Initializes yew framework. It should be called first.

run_loop

Starts event loop.

start_app

Starts an app mounted to a body of the document.

start_app_with_props

Starts an app mounted to a body of the document.