intendednull / yewdux

Ergonomic state management for Yew applications
https://intendednull.github.io/yewdux/
Apache License 2.0
322 stars 31 forks source link

no function or associated item named `global` found for struct `yewdux::Dispatch` #73

Open einsli opened 10 months ago

einsli commented 10 months ago

I write code with given example Default Value, an error occured

no function or associated item named `global` found for struct `yewdux::Dispatch`

here is my code

use yewdux::prelude::*;

#[derive(PartialEq, Store)]
struct MyStore {
    foo: String,
    bar: String,
}

impl Default for MyStore {
    fn default() -> Self {
        Self {
            foo: "foo".to_string(),
            bar: "bar".to_string(),
        }
    }
}
fn main() {
    let foo = "foo".to_string();
    let bar = "bar".to_string();
    // Run this before starting your app.
    Dispatch::<MyStore>::global().set(MyStore { foo, bar });
}

here is the Cargo.toml

[dependencies]
yewdux = "0.10.0"

I want to know if I should turn on a certain feature?

intendednull commented 10 months ago

Global context is disabled for non-wasm targets. If you don't need SSR support, you can set the default build target for your project.

If you do need SSR support, please review the docs

accorded-jay commented 9 months ago

We ran into the same issue even with targeting wasm32-unknown-unkown. We had to turn on the doctests feature to get it to work. Adding yewdux = { version = "0.10.0", features = ['doctests']} got us past this issue, but it does seem odd that it's gated behind that particular feature.

intendednull commented 8 months ago

@accorded-jay that feature is for internal use, and shouldn't be necessary. Can you share your project, or a minimal reproduction?

Using global in non-wasm targets can introduce unexpected behavior, and is not recommended.

LucaCappelletti94 commented 8 months ago

I have encountered the same issue while writing a very much WASM yew lil thing.

intendednull commented 8 months ago

@LucaCappelletti94 This might be happening when building the whole project, which probably defaults to your native target. You should be able to compile by specifying the target for your wasm crate only. However, I can see how this might get cumbersome.

Will see about a qol improvement here

LucaCappelletti94 commented 8 months ago

I think it is a rust analyzer issue, which currently does not seem to support the config files for subcrates.

TaoVonQi commented 7 months ago

Yes, trunk builds fine but rust analyzer complains.