admin管理员组文章数量:1394990
I have a simple question. I have a REACTjs application which does some requests to the API when starting. These requests are usually done only once but once in a while, user might want to refresh the application manually.
When performing ctrl+F5 (or refresh the page via browser), it works fine.
I tried adding a button with the same functionality like this to my application:
<button value="Refresh Page" onClick="window.location.reload(true)">Refresh</button>
but it only performs two requests: 0.junk.js
and 0.junk.js.map
which both returns 304 status.
Is there a way how to achieve the same behavior as refreshing with browser?
I have a simple question. I have a REACTjs application which does some requests to the API when starting. These requests are usually done only once but once in a while, user might want to refresh the application manually.
When performing ctrl+F5 (or refresh the page via browser), it works fine.
I tried adding a button with the same functionality like this to my application:
<button value="Refresh Page" onClick="window.location.reload(true)">Refresh</button>
but it only performs two requests: 0.junk.js
and 0.junk.js.map
which both returns 304 status.
Is there a way how to achieve the same behavior as refreshing with browser?
Share Improve this question asked Mar 19, 2019 at 9:47 SmajlSmajl 8,01532 gold badges113 silver badges182 bronze badges2 Answers
Reset to default 5Try calling a function:
onClick={() => window.location.reload(true)}
Or Simply update any state of your main ponent:
this.setState({ refresh: true })
I don't think a string like that is a valid prop you can pass to an onClick
. That looks like the way you would do it using plain old html. You would have to pass a function to onClick
like <button value="Refresh Page" onClick={() => window.location.reload(true)}>
本文标签: javascriptForce refresh REACTjs application the same way as ctrlF5Stack Overflow
版权声明:本文标题:javascript - Force refresh REACTjs application the same way as ctrl+F5 - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744109055a2591203.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论