Skip to content

Commit

Permalink
Add a mounted example (yewstack#1185)
Browse files Browse the repository at this point in the history
* Add a `mounted` example

* Update mod.rs

* Fix documentation typos
  • Loading branch information
TheNeikos committed May 11, 2020
1 parent 31135f1 commit b13605e
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions yew/src/html/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,23 @@ pub trait Component: Sized + 'static {

/// The `rendered` method is called after each time a Component is rendered but
/// before the browser updates the page.
/// ## Examples
/// ```rust
///# use yew::{Html, Component, ComponentLink, html, ShouldRender};
///# struct Model{props: ()};
///# impl Model { fn setup_element(&self) { } }
///# impl Component for Model {
///# type Message = ();type Properties = ();
///# fn create(props: Self::Properties,link: ComponentLink<Self>) -> Self {unimplemented!()}
///# fn update(&mut self,msg: Self::Message) -> bool {unimplemented!()}
///# fn view(&self) -> Html {unimplemented!()}
///# fn change(&mut self, _props: Self::Properties) -> ShouldRender { unimplemented!() }
/// fn rendered(&mut self, first_render: bool) {
/// if first_render {
/// self.setup_element(); // Similar to 'mounted' in other frameworks
/// }
/// }
///# }
fn rendered(&mut self, _first_render: bool) {}

/// The `destroy` method is called right before a Component is unmounted.
Expand Down

0 comments on commit b13605e

Please sign in to comment.