#Managed state: You must call `.manage()` before using this command

15 messages · Page 1 of 1 (latest)

shrewd lark
#

Im going over what i see in the docs but don't know what to do past passing in my state.

Anyone have a direction to point me in to dig in more?

let app = tauri::Builder::default()
        .menu(menu)
        .manage(connections)
        .invoke_handler(tauri::generate_handler![execute,test_connection,connect])
        .run(tauri::generate_context!())
        .expect("error while running tauri application");
glacial wedge
#

can you also show where you're trying to access the state,

and the type of connections you give to .manage

shrewd lark
#

  const unlisten  = async () => {
    await listen('connect', (event) => {
      router.push(event.payload);
    })
  }
  
  useEffect(()=>{
    unlisten().then((e)=>{console.log(e)})
  },[])
#

oh wrong code

#
fn execute(state: tauri::State<HashMap<String,Driver>>, sql: &str) ->  TauriToadReturn{
    let t = state.get("test").unwrap().to_owned();
    match t {
        Driver::Mysql(_)=>println!("{}","mysql".to_owned()),
        _=>panic!("nah bro")
    }
#

connection type:

let mut connections: HashMap<&str,Driver> = HashMap::new();
cloud rune
#

You put String in the type in your command but &str in the definition of your type

shrewd lark
#

changed it to &"test".to_string() but i still get the same error.

#

We make it to runtime, and all other functionalities work. But when i call the #[tauri::command] that reliese on the state it blow us

glacial wedge
# shrewd lark changed it to `&"test".to_string()` but i still get the same error.

what squitch meant is this one: ```rs
let mut connections: HashMap<&str,Driver> = HashMap::new();

`HashMap<&str, Driver>` is not the same as `HashMap<String, Driver>` (the latter is what you're using in your command). The types must match because the types are basically the IDs of the state and used to get the correct value from tauri's state store
shrewd lark
#

ah

shrewd lark
#

Thanks that is super helpful. If i want to make a PR to add this to the docs, is that something y'all want?

shrewd lark
#

@cloud rune @glacial wedge Can i mutate the state in the functions the state is passed to?

glacial wedge
#

you'll need a Mutex or something similar for interior mutability