score:0

Here's one way of doing it using React Bootstrap and a component that you can then drop into any page...

import Button from 'react-bootstrap/Button';

export const RefreshCurrentPage = () => {

  function refreshPage(){ 
    window.location.reload(); 
  }

  return (
    <div className="row">
      <Button onClick={ refreshPage } variant="secondary" size="sm" className="btn ml-4">Refresh Page</Button>
    </div>

  );

}

score:1

You can simply run this after successful query.

window.location.reload();

score:6

You can use this

<a onClick={() => {window.location.href="/something"}}>Something</a>

score:6

I ended up keeping Link and adding the reload to the Link's onClick event with a timeout like this:

function refreshPage() {
    setTimeout(()=>{
        window.location.reload(false);
    }, 500);
    console.log('page to reload')
}

<Link to={{pathname:"/"}} onClick={refreshPage}>Home</Link>

without the timeout, the refresh function would run first

score:42

Try like this.

You must give a function as value to onClick()

You button:

<button type="button" onClick={ refreshPage }> <span>Reload</span> </button> 

refreshPage function:

function refreshPage(){ 
    window.location.reload(); 
}

score:192

To refresh page you don't need react-router, simple js:

window.location.reload();

To re-render view in React component, you can just fire update with props/state.


Related Query

More Query from same tag