Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue interpolating components #184

Closed
martsec opened this issue Jan 19, 2025 · 4 comments
Closed

Issue interpolating components #184

martsec opened this issue Jan 19, 2025 · 4 comments

Comments

@martsec
Copy link

martsec commented Jan 19, 2025

Hi, I'm using the latest version of the library (v0.5.5), CSR leptos (v0.7.4) and rust nightly and I'm having a bit of an issue when I want to replicate the examples to interpolate html components. Can any one help me see what is wrong?

My code is the following

use leptos::prelude::*;
use crate::i18n::*;

#[component]
fn TestHtml() -> impl IntoView {

    let i18n = use_i18n();

    let (counter, _set_counter) = signal(0);
    let count = move || counter.get();
    let b = |children| view!{ <b>{children}</b> };

    view! {
        {/* "click_count": "you clicked <b>{{ count }}</b> times" */}
        <p>{t!(i18n, cata.click_count, count, <b>)}</p>
    }
}

and I'm using namespaces so the file is locales/en/cata,json

{
    "click_count": "you clicked <b>{{count}}</b> times",
   ...
}

I get the following error, and it does not go away if I try another option

error[E0277]: the trait bound `Arc<dyn Fn() -> AnyView + Send + std::ma
rker::Sync>: IntoRender` is not satisfied
   --> src/views/cata.rs:318:74
    |
318 | ...= |children| view!{ <b>{children}</b> })}</p>
    |                 ----------^--------^------
    |                 |         ||
    |                 |         |this tail expression is of type `Arc<d
yn Fn() -> AnyView + Send + Sync>`
    |                 |         the trait `FnMut()` is not implemented 
for `Arc<dyn Fn() -> AnyView + Send + std::marker::Sync>`, which is req
uired by `Arc<dyn Fn() -> AnyView + Send + std::marker::Sync>: IntoRend
er`
    |                 required by a bound introduced by this call

...

error[E0599]: the method `into_view` exists for struct `click_count_bui
lder<{[email protected]:318:53}, ..., ...>`, but its trait bounds were no
t satisfied
   --> src/views/cata.rs:318:13
    |
318 | ...p>{t!(i18n, cata.click_count, count, <b> = |children| view!{ <
b>{children}</b> })}<...
    |       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
^^^^^^^^^^^^^^^^^^^
    |
   ::: src/main.rs:11:1
    |
11  | leptos_i18n::load_locales!();
    | ---------------------------- method `into_view` not found for thi
s struct because it doesn't satisfy `_: IntoView`, `_: RenderHtml` or `
_: Render`
    |
   ::: /home/marti/.cargo/registry/src/index.crates.io-6f17d22bba15001f
/leptos-0.7.4/src/into_view.rs:14:1
    |
14  | pub struct View<T>
    | ------------------ doesn't satisfy `_: IntoView`, `_: RenderHtml`
 or `_: Render`

Even if I force the type let b = |children: ChildrenFn| view!{ <b>{children}</b> }; returns me a similar error. Any guidance on this will be appreciated since I'm not quite understanding what I'm doing wrong here.

@Baptistemontan
Copy link
Owner

Baptistemontan commented Jan 19, 2025

With Leptos v0.7 a bunch of things changed so some examples may not compile anymore, I'm sorry for that, I'll try to find the time to update them.

You can solve your problem by wrapping children in a closure and call it:

#[component]
pub fn TestHtml() -> impl IntoView {
    let i18n = use_i18n();

    let (counter, _set_counter) = signal(0);
    let count = move || counter.get();
    let b = |children: ChildrenFn| view! { <b>{move || children()}</b> };

    view! {
        {/* "click_count": "you clicked <b>{{ count }}</b> times" */}
        <p>{t!(i18n, cata.click_count, count, <b>)}</p>
    }
}

@Baptistemontan
Copy link
Owner

Baptistemontan commented Jan 19, 2025

By the way, in this exact example you could just do t!(i18n, click_count, count, <b> = <b />) and won't need to create the b closure yourself.

@martsec
Copy link
Author

martsec commented Jan 19, 2025

Oh, no worries, thank you very much! If I can find some time this week i can create a PR to update them 😄

@Baptistemontan
Copy link
Owner

Hello, is this issue solved? If yes can you close it ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants