简体   繁体   English

使用 reactjs 禁用刷新

[英]Disable Refresh with reactjs

anybody knows how to disable refresh.任何人都知道如何禁用刷新。 the following does not seem to work.以下似乎不起作用。

window.addEventListener("beforeunload", () => { 
    return false; 
});

Probably the best thing you can do (with respect to you wanting to prevent a user from accidentally leaving the voice call) is to show them a message they have to confirm before they leave.您能做的最好的事情(相对于您想要防止用户意外离开语音通话)可能是在他们离开之前向他们显示一条必须确认的消息。 Try this:试试这个:

window.onbeforeunload = ()=>"If you leave this page, you'll also leave the call";

Maybe you can also do that in the addListener syntax you already tried (simply return a string instead of false and change onunload to onbeforeunload).也许您也可以在已经尝试过的 addListener 语法中执行此操作(只需返回一个字符串而不是 false 并将 onunload 更改为 onbeforeunload)。

这是在components类中通过shouldComponentUpdate函数完成的,在use中通过输入参数实现,虽然可以通过rect.memo和纯组件来控制,使用回调和使用memo

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM