You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The new 0.6 syntax makes it impossible to activate the initial state of an application without breaking the rules for using hooks.
Using the 0.5 application initial syntax, use_context_provider initializes the creation of the initial application state inside the function:
fn App() -> Element {
use_context_provider(|| Signal::new("en".to_string()))
}
The new syntax is like a street with two red lights on it, where you can’t initialize state without breaking the hook rules, because launch is a closure and causes a hook error.
fn main () {
use_context_provider(|| Signal::new("en".to_string()))
launch(|| {
rsx! {
// Your component code here
}
});
}
Has an error: hook called outside component or hook
launch(|| {
use_context_provider(|| Signal::new("en".to_string()))
rsx! {
// Your component code here
}
});
Has an errors hook called in a closure and hook called outside component or hook
Environment:
Dioxus version: 0.6 from git
Rust version: rustc 1.81.0
OS info: win11
App platform: web
The text was updated successfully, but these errors were encountered:
RustGrow
changed the title
New Syntax Prevents Initial State Activation Without Breaking Hook Rules
The new syntax does not allow you to create an initial state without violating the hook creation rules
Sep 18, 2024
fnmain(){// If you need to load from env vars or etclet locale = String::from("en");launch(move || {rsx!{App{ locale: locale.clone()}}});}#[component]fnApp(locale:String){use_context_provider(|| Signal::new(locale))// Your component code here}
Evan says it's fine and the rules are not broken, but because the app is not directly defined as a component. dx check will constantly generate a signals violation error
The new 0.6 syntax makes it impossible to activate the initial state of an application without breaking the rules for using hooks.
Using the 0.5 application initial syntax, use_context_provider initializes the creation of the initial application state inside the function:
The new syntax is like a street with two red lights on it, where you can’t initialize state without breaking the hook rules, because
launch
is a closure and causes a hook error.Has an error: hook called outside component or hook
Has an errors
hook called in a closure
andhook called outside component or hook
Environment:
The text was updated successfully, but these errors were encountered: