How to build a custom reusable hook with some return other than view? #2266
Unanswered
silicology1
asked this question in
Q&A
Replies: 1 comment
-
Instead of your hook returning a use leptos::*;
pub fn sign_in_with_extension() -> ReadSignal<String> {
let (name, set_name) = create_signal(String::from(""));
create_effect(move |_| {
set_name("Rikesh".to_string());
// immediately prints "Value: 0" and subscribes to `a`
gloo::console::log!(format!("Value: {}", name()));
});
name
}
#[component]
pub fn ExtensionSignIn() -> impl IntoView {
let name = sign_in_with_extension();
view! {
<div>
<code>{move || format!("{:#?}", name())}</code>
</div>
}
} |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Following code works
Following don't doesn't work
Beta Was this translation helpful? Give feedback.
All reactions