Alan AI Error Uncaught Error: The Alan Button instance has already been created. There cannot be two Alan Button instances created at the same time

Alan AI Error Uncaught Error: The Alan Button instance has already been created. There cannot be two Alan Button instances created at the same time

我正在使用 Alan AI 开发一个电子商务网站 AI 驱动的语音命令。但是每当我从另一条路线回来时,控制台都会显示一个空白页面 appears.and 此错误消息: “未捕获的错误:已经创建了 Alan Button 实例。不能同时创建两个 Alan Button 实例”。我能做什么? 我的代码如下:

const Alan = () => {

    useEffect(() => {
        alanBtn({
            key: alanKey,
            onCommand: ({ command }) => {
                if (command === 'testCommand') {
                    alert('This code was executed');
                }
            }
        })
    }, [])

    return (
        <div>

        </div>
    );
};

这很关键但很简单...!

使用 requestAnimationFrame 进行网页视觉更改。

如果 运行 作为 requestAnimationFrame 回调,这将是帧开始处的 运行。

const Alan = () => {
  useLayoutEffect(() => {
    function updateScreen(time) {
      // Make visual updates here.
      alanBtn({
        key: alanKey,
        onCommand: ({ command }) => {
          if (command === 'testCommand') {
            alert('This code was executed');
          }
        }
      })
    }

    requestAnimationFrame(updateScreen);
  }, [])

  return (
    <div>

    </div>
  );
};