user

Joseph Morgan

8 Feb 2022

Reload browser window using Reactjs?

React js

Hello everyone,
Please How can I refresh the page (reload the window) using Reactjs?

Thanks in advanced

Comments

Mohamed Atef

8 Feb 2022

Best Answer

best answer
githubgithubgithub

You can do it using a button or any function like 

<Button size="medium" variant="text" onClick={ () => { window.location.reload(); } } startIcon={<ArrowBackIosIcon /> }>
 Start from beginning
</Button> 
import React from 'react';
import Page from 'src/components/Page';
import { 
 Grid,
 withStyles 
} from '@material-ui/core';
import { withSnackbar } from 'notistack';
import { withRouter } from 'react-router-dom';
import ArrowBackIosIcon from '@material-ui/icons/ArrowBackIos';

const styles = (theme) => ({
 root:{
 paddingTop: '31px',
 minHeight: '90vh',
 }
});

class Quiz extends React.Component {

 render(){
 return(
 <Page title="Reload page">
 <Container maxWidth="lg">
 <Grid container>
 <Grid item md={2} xs={12}/>
 <Grid item md={3} xs={12}></Grid>
 <Grid item md={6} xs={12}>
 <Box display="flex" pb={5}>
 <Button size="medium" variant="text" onClick={ 
 () => { 
 	this.props.history.push('/search-by-goal/'); 
 	window.location.reload(); 
 } } startIcon={<ArrowBackIosIcon /> }>
 Start from beginning
 </Button> 
 </Box>
 </Grid>
 <Grid item md={2} xs={12}/>
 </Grid>
 </Container>
 </Page>
 );
 }
}
export default withSnackbar(withStyles(styles)(withRouter(Quiz)));

Thats all 

Replies

Joseph Morgan

8 Feb 2022

Great, Thanks

Mohammed Bal'awi

9 Feb 2022

You can use :

window.location.reload()

This will reload the page from the cache

If you want to reload from server just use :

window.location.reload(true)

Hope this helpful.

 

Replies

Jo Micheal

9 Feb 2022

That's it, Thank you for clarification 

© 2023 Copyrights reserved for web-brackets.com