DioxusLabs / DioxusLabs/dioxus
The new syntax does not allow you to create an initial state without violating the hook creation rules
- Dominant language
- Rust
- Stars
- 39.1k
- Forks
- 1.9k
- Avg merge
- 4d 10h
- Merged PRs (30d)
- 4
Description
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
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.