【发布时间】:2021-09-17 12:11:06
【问题描述】:
我有一个初学者的反应问题。我知道这可能有一个解释,但我已经尝试了两天没有运气。所以我们开始吧。我做了这个导航栏:
如您所见,每次使用导航时菜单都会关闭。以下代码负责导航:
const OnClickNav = (index: string, dispatch) => {
const runValidations = null;
dispatch(FormLayoutActions.updateCurrentView({ newView: index, runValidations }));
};
我希望菜单在导航功能运行后保持打开状态,但状态变量“mounted”总是重置为false。在这里你可以看到代码:
const [mounted, setMounted] = useState(false);
所以发生的事情是调度运行并且状态变量设置为false。我希望它在导航后保持“真”值,我该如何实现?
【问题讨论】:
-
添加更多代码。
useState在哪里?mounted在哪里使用?您希望导航何时压缩?
标签: reactjs typescript redux