Skip to content

Commit

Permalink
render props
Browse files Browse the repository at this point in the history
  • Loading branch information
ChristopherBiscardi committed Sep 30, 2023
1 parent 832971c commit 5ae9927
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
3 changes: 3 additions & 0 deletions index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ h1 + .subtitle {
}

.input {
border-right: 1px solid #00000044;
min-width: 200px;
padding-right: 2rem;
display: flex;
flex-direction: column;
justify-content: center;
Expand Down
43 changes: 42 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ use oneshot::FibonacciTask;
pub mod reactor;
use reactor::TimeFormatReactor;
use web_sys::HtmlInputElement;
use yew::{platform::spawn_local, prelude::*};
use yew::{
html::ChildrenRenderer, platform::spawn_local,
prelude::*, virtual_dom::VNode,
};
use yew_agent::{
oneshot::{use_oneshot_runner, OneshotProvider},
reactor::{use_reactor_subscription, ReactorProvider},
Expand All @@ -23,6 +26,9 @@ pub fn app() -> Html {
</div>
<OneShotExample/>
<ReactorExample/>
<RenderPropExample>
{|p: RenderProps| html!{<>{"Hello, "}{p.name}</>}}
</RenderPropExample>
</main>
</ReactorProvider<TimeFormatReactor>>
</OneshotProvider<FibonacciTask>>
Expand Down Expand Up @@ -127,3 +133,38 @@ pub fn one_shot_example() -> Html {
</div>
}
}

#[derive(Properties, PartialEq, Clone)]
pub struct RenderProps {
pub name: AttrValue,
}

#[derive(Properties, PartialEq)]
pub struct ComponentProps {
pub children: Callback<RenderProps, Html>,
}

#[function_component(RenderPropExample)]
pub fn render_prop_example(p: &ComponentProps) -> Html {
let render_props = RenderProps {
name: "chris".into(),
};
html! {
<div class="ww-container">
<ul class="input">
<li>
{p.children.emit(render_props.clone())}
</li>
<li>
{p.children.emit(render_props.clone())}
</li>
<li>
{p.children.emit(render_props)}
</li>
</ul>
<div class="display">
<h2>{"Render Props"}</h2>
</div>
</div>
}
}

0 comments on commit 5ae9927

Please sign in to comment.