Skip to content

Use view macro for composing components with htmx #1757

Answered by gbj
ejazahm3d asked this question in Q&A
Discussion options

You must be logged in to vote

If you compare your version to my version above, you'll see that you have a stray semicolon:

let res = render_to_string(move || {
    view! {
        <ByeWorld  text=8 />
        <div>"Hello World"</div>
    }; // HERE
});

This means that what is returned from the closure inside render_to_string is not your view, but the unit type (), which is (helpfully? unhelpfully?) rendered as an empty HTML string. (It's important that () implements IntoView for Reasons, but occasionally causes this footgun.)

if you remove that semicolon it should work as you intended.

Replies: 2 comments 5 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
5 replies
@gbj
Comment options

gbj Sep 19, 2023
Maintainer

@gbj
Comment options

gbj Sep 19, 2023
Maintainer

@ejazahm3d
Comment options

@gbj
Comment options

gbj Sep 20, 2023
Maintainer

Answer selected by ejazahm3d
@ejazahm3d
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants