Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Force refresh REACTjs application the same way as ctrl+F5

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?

like image 290
Smajl Avatar asked Dec 31 '25 07:12

Smajl


1 Answers

Try calling a function:

onClick={() => window.location.reload(true)}

Or Simply update any state of your main component:

this.setState({ refresh: true })
like image 129
Muhammad Abdullah Shafiq Avatar answered Jan 03 '26 11:01

Muhammad Abdullah Shafiq



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!