如何从javascript中的另一个模块访问局部变量

时间:2020-08-08 19:50:38

标签: javascript reactjs module local-variables

我想创建一个注销功能,该功能应该重置所有计数器。因此,我需要从另一个模块访问反变量(并将它们设置为原始值)。如何在javascript中做到这一点并做出反应?

这是我的导入声明和AuthState.js文件中的logoutUser函数:

import chatState from "../Chat/ChatState";

const logoutUser = () => {
    console.log(questioncounter);
    chatState.questioncounter = 2;
    chatState.questioncounter_event = 1;
    chatState.currentNode = 1;

    dispatch({
      type: LOGOUT_USER,
    });
  };

这是ChatState.js中的局部变量:

let questioncounter = 2;
let questioncounter_event = 1;
let currentNode = 1;

0 个答案:

没有答案