intendednull/yewdux

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

Opened this issue · 7 comments

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?

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

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.

@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.

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

@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

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

Yes, trunk builds fine but rust analyzer complains.