You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I wrote the following code using next.js, which uses the useEffect of React. But the code doesn't work, when refreshing the page alert("unlisten: " + unlisten) always results in "unlisten: undefined", causing the number of listens to increase with each refresh. Can anyone tell me what I should do to get unlisten to work?
"use client";import{invoke}from"@tauri-apps/api/core";import{useEffect}from"react";import{listen}from"@tauri-apps/api/event";exportdefaultfunctionPage(){functionmsgHandler(msg){console.log(msg);}useEffect(()=>{letunlisten;listen("event",msgHandler).then((unlisten_)=>{unlisten=unlisten_;});return()=>{alert("unlisten: "+unlisten);if(unlisten){unlisten();}};},[]);return(<>{/* This button invoke app.emit("event","msg") */}<buttononClick={()=>{invoke("emit","msg");}}>
emit
</button></>);}
Describe the bug
I wrote the following code using next.js, which uses the useEffect of React. But the code doesn't work, when refreshing the page
alert("unlisten: " + unlisten)
always results in "unlisten: undefined", causing the number of listens to increase with each refresh. Can anyone tell me what I should do to get unlisten to work?Reproduction
https://github.com/canxin121/test_emit
Expected behavior
Before the page is refreshed, unlisten should already be a function and not undefined, and then unlisten is called normally.
Full
tauri info
outputStack trace
Additional context
No response
The text was updated successfully, but these errors were encountered: