I'm trying to create an event listener for every command I have in Tauri(Rust). Also I'm not sure if this is the best pattern to follow.
The main problem is that when I emit an event from tauri, the front-end in react doesn't display anything.
JS:
useEffect(() => {
const unlisten_register = listen('register', (event: any) => {
console.log('REGISTER', event);
});
return () => {
unlisten_register.then((unlisten) => unlisten());
};
}, []);
This function is used in my custom command.
Rust:
async fn send_response(
packet_name: &str,
packet: BytesMut,
window: tauri::Window,
) -> Result<(), Box<dyn Error>> {
let _ = window.emit_all(
packet_name,
serde_json::to_string(&bincode2::deserialize::<InternalServiceResponse>(&packet)?)?,
);
Ok(())
}```