Replies: 8 comments 5 replies
-
Do you mean that the |
Beta Was this translation helpful? Give feedback.
-
It is okay re-importing the whole JS file, as the file basically modulates a html element. My problem is with triggering events. How can I trigger an event in this psuedo-page load? |
Beta Was this translation helpful? Give feedback.
-
I do not think that triggering an event is what you want here. If you just want to run some code whenever this component is rendered you could use #[component]
pub fn Banner() -> impl IntoView {
let (loaded, load_up) = create_signal(false);
create_effect(move |_| {
load_up(true);
});
view ! {
<Show when=move || loaded.get() == true>
<Script type_="module" src="/scripts/banner.js"></Script>
</Show>
}
} |
Beta Was this translation helpful? Give feedback.
-
This does not re-load the element after returning back from another page unless I refresh the page or type in the URL directly. |
Beta Was this translation helpful? Give feedback.
-
I suspect that is because rendering the same |
Beta Was this translation helpful? Give feedback.
-
I converted this to a discussion to take it out of the issue tracker, as I don't think there's any underlying issue with the framework here. Feel free to let me know if you're looking for additional help. |
Beta Was this translation helpful? Give feedback.
-
So, I have a bit of the same problem here. #[component]
fn ShowTable(data: Signal<Vec<Data>>) -> impl IntoView {
{
move || {
view! {
<Transition fallback=move || {
view! { <BallSpinner h=40/> }
}>
<Show
when=move || !data().is_empty()
fallback=|| {
view! { <p>"Nothing to show"</p> }
}
>
<p>"There are " {data().len()} " elements"</p>
</Show>
</Transition>
}
}
}
} If I begin on the page with this component (either a reload initiated by the server, or manually), no event fires anywhere else: buttons, links, etc. Nothing happens (in the case of the links, the address bar is updated, but the browser doesn’t do anything with it). A point of interest: if I remove the And another thing that might be important: I’m using leptos_query to load the data: let QueryResult { data, .. } = use_query(
|| (),
|_| async move { get_currencies().await.unwrap_or_default() },
QueryOptions {
stale_time: Some(Duration::from_secs(60)),
..Default::default()
},
);
let data: Signal<Vec<Data>> = Signal::derive(move || data.get().unwrap_or_default()); Am I doing something wrong or is there a problem somewhere? Edit: #[component]
pub fn DataCard() -> impl IntoView {
let params = use_params::<DataParam>();
let key = params().map(|p| p.id).unwrap();
let loader = create_resource(move || key, get_data);
view! {
<ErrorBoundary fallback=|errors| {
view! { <ErrorMessage msg=MaybeSignal::Static("couldn’t get data") errors=errors/> }
}>
<Transition fallback=move || {
view! { <BallSpinner h=20/> }
}>
{move || {
loader
.get()
.map(|mint| data.map(|data| data))
.unwrap_or(Ok(Data::default()))
.unwrap_or(Data::default())
.random_field
}}
</Transition>
</ErrorBoundary>
<Outlet/>
}
} Maybe that’s because of the ugly stuff I have to do to actually get my data? |
Beta Was this translation helpful? Give feedback.
-
I'm trying to load a script and update a signal from the use std::collections::HashSet;
use leptos::*;
use leptos_meta::*;
use leptos_router::*;
#[derive(Clone)]
pub struct JsLibs(pub ReadSignal<HashSet<String>>);
#[component]
pub fn App() -> impl IntoView {
// Provides context that manages stylesheets, titles, meta tags, etc.
provide_meta_context();
let (js_libs, set_js_libs) = create_signal(HashSet::new());
provide_context(JsLibs(js_libs));
view! {
<Stylesheet id="leptos" href="/pkg/style.css"/>
<Script defer={"defer"} on:load={move |_| {
// never gets here
log::info!("loaded rive");
set_js_libs.update(|s| {s.insert("Rive".to_string());})
}} src="https://unpkg.com/@rive-app/[email protected]"/>
<div class="font-sans h-screen w-screen overflow-hidden flex flex-col bg-stone-300 dark:bg-stone-950 text-slate-950 dark:text-slate-50">
<Router>
<Routes>
<Route path="/:lang" view=LocalizedView>
...
</Route>
<Route path="/*any" view=NotFound/>
</Routes>
</Router>
</div>
}
} |
Beta Was this translation helpful? Give feedback.
-
Describe the bug
I have a function which loads a threejs file to display an interface. This works fine when loading a single page, but after I visit another page and return back to it, the element disappears.
Leptos Dependencies
To fix this, I tried loading it on pageshow and load (as events) and neither trigger on pageload, leaving the script always unloaded.
Relevant Code
Help would be appreciated. I can provide more details if needed.
Beta Was this translation helpful? Give feedback.
All reactions