Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
einsli opened this issue Dec 28, 2023 · 7 comments

Comments

@einsli
Copy link

einsli commented Dec 28, 2023

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
Copy link
Owner

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
Copy link

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
Copy link
Owner

intendednull commented Feb 15, 2024

@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
Copy link

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

@intendednull
Copy link
Owner

@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
Copy link

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

@TaoVonQi
Copy link

Yes, trunk builds fine but rust analyzer complains.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants