DioxusLabs / dioxus

Fullstack app framework for web, desktop, mobile, and more.
https://dioxuslabs.com
Apache License 2.0
20.32k stars 779 forks source link

Using #[inline_props] with SSR #1645

Closed 9876691 closed 10 months ago

9876691 commented 10 months ago

I can see how to use #[inline_props] but not sure how to then pass this to VirtualDom for rendering (SSR).

So the example below doesn't compile.

pub fn index(organisation_id: i32) -> String {

    #[inline_props]
    fn app(cx: Scope, organisation_id: i32) -> Element {
        cx.render(rsx! {
            div {
                "{organisation_id}"
            }
        })
    }

    // What do I do here?
    VirtualDom::new_with_props(app, Props { organisation_id })
}
ealmloff commented 10 months ago

inline_props takes the function name, adds Props and creates a new props struct with that name. So your app component will have an autogenerated appProp struct.

pub fn index(organisation_id: i32) -> String {
    #[inline_props]
    fn app(cx: Scope, organisation_id: i32) -> Element {
        cx.render(rsx! {
            div {
                "{organisation_id}"
            }
        })
    }

    VirtualDom::new_with_props(app, appProps { organisation_id });
    todo!()
}