We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
I'm trying to use the use_websocket_with_options hook to send a message immediately upon connecting to the server.
use_websocket_with_options
#[function_component(App)] pub fn app() -> Html { let ws = yew_hooks::use_websocket_with_options( "ws://mywebsocket".into(), yew_hooks::UseWebSocketOptions { onopen: Some(Box::new(|_| { // This doesn't compile ws.send("test".into()); })), ..Default::default() }, ); html! { <main> </main> } }
How can I access ws from inside of this closure? UseWebSocketHandle doesn't have a way to change the websocket callbacks after initialization.
ws
UseWebSocketHandle
Update:
I managed to work around it using use_effect_with_deps:
use_effect_with_deps
let addr = "ws://mywebsocket"; let ws = use_websocket(addr.into()); { let ws = ws.clone(); let ready_state = ws.ready_state.clone(); use_effect_with_deps( move |ready_state| { if **ready_state == UseWebSocketReadyState::Open { info!("Open"); ws.send("a".into()); } }, ready_state, ); }
The text was updated successfully, but these errors were encountered:
No branches or pull requests
I'm trying to use the
use_websocket_with_options
hook to send a message immediately upon connecting to the server.How can I access
ws
from inside of this closure?UseWebSocketHandle
doesn't have a way to change the websocket callbacks after initialization.Update:
I managed to work around it using
use_effect_with_deps
:The text was updated successfully, but these errors were encountered: