Joseph Morgan Published in : 2022-02-08
React js
Hello everyone,Please How can I refresh the page (reload the window) using Reactjs?
Thanks in advanced
Mohamed Atef Date : 2022-02-08
Best answers
51
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
Joseph Morgan Date : 2022-02-08
Great, Thanks
Mohammed Bal'awi Date : 2022-02-09
1
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.
Jo Micheal Date : 2022-02-09
That's it, Thank you for clarification
Please Login or sign up to be able to write comment
Join our community and get the chance to solve your code issues & share your opinion with us
Tag: React js
Mohamed Atef Date : 2022-02-08
Best answers
51
Best answers
51
You can do it using a button or any function like
Thats all
Joseph Morgan Date : 2022-02-08
Great, Thanks
Mohammed Bal'awi Date : 2022-02-09
Best answers
1
Best answers
1
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.
Jo Micheal Date : 2022-02-09
That's it, Thank you for clarification