Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to reload current page in ReactJS?

How to reload current page in ReactJS? in case of javascript we can write window.location.reload(); How to do the same in Reactjs? I'm able to add new data by UI. But without refreshing, I'm not able to see the list. I want it so that whenever I'm adding some data, it refreshes by itself.

onAddBucket() {     let self = this;     let getToken = localStorage.getItem('myToken');     var apiBaseUrl = "...";     let input = {       "name" :  this.state.fields["bucket_name"]     }     axios.defaults.headers.common['Authorization'] = getToken;     axios.post(apiBaseUrl+'...',input)     .then(function (response) {        if(response.data.status == 200){       let result =  self.state.buckets.concat(response.data.buckets)       }else{         alert(response.data.message);       }     })     .catch(function (error) {       console.log(error);     });   } 
like image 723
Riya Kapuria Avatar asked Nov 09 '17 12:11

Riya Kapuria


People also ask

How do you refresh a page?

While holding, press refresh ⟳. Using Chrome on mobile, go to ⋮ (Android) or … (iOS) > Settings > Privacy > Clear Browsing Data > Clear Browsing Data (iOS) or Clear Data (Android).

How do you refresh a page in JavaScript?

You can use the location. reload() JavaScript method to reload the current URL. This method functions similarly to the browser's Refresh button. The reload() method is the main method responsible for page reloading.


1 Answers

use this might help

window.location.reload(); 
like image 77
Nisal Edu Avatar answered Sep 17 '22 14:09

Nisal Edu