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.
Source: stackoverflow.com
Related Query
- How to refresh a Page using react-route Link
- How to make Meteor React inline svg element click link to page without refresh whole page
- How to access previous index route in nested routes using Link component from react router?
- How to link to another page using react router?
- Im using React Router and I want one of my route links with path="/" to be the home page on reload.. How can you do that?
- How to reload a page using react router Link component?
- How to link to certain page upon form submission using React Router
- React JS refresh page every time clicking on menu item using route
- How do I make my parent component re-run an api call on page refresh using React Router?
- how to pass parameters to component using react route link
- i'm using react hook useEffect to fetch an advice api. it changed automatically after every page refresh how can i do it automaticly using a button
- How can I get my React App to correctly send page title in link previews? Using NGINX as proxy
- Page wont refresh when using React Link and passing state
- How to navigate from one link to another inside same page using React URL hash or route?
- How to create multiple page app using react
- React | How to detect Page Refresh (F5)
- How to pass params into link using React router v6?
- How to pass the match when using render in Route component from react router (v4)
- How to stream webcam feed on web page using react js component?
- How to create a preview (Image and description) to the Url when shared link on Social media,Gmail and Skype using React JS?
- How to format time in React SSR rendered page using client time zone?
- React Link doesn't refresh the page
- How to create unique key for NavigationStateUtils using push route in React Native/Redux?
- React Flash Message: How to make the message show without refreshing the page but refresh on 200
- ReactJS - Route update link but not refresh page
- how to pass props to the route when using react router <Link>
- How do I access data returned from an axios get to display on a web page using react js?
- How to set route with optional query parameter using React router?
- How to add page transitions to React without using the router?
- How to pass data from a page to another page using react router
More Query from same tag
- Image paths are not resolved within component that gets parameters from the url
- react-select: Is it possible to add animated components and custom components simultaneously?
- react native show current time and update the seconds in real-time
- In Typescript, is there any way to typecheck passed-in JSX.Element's?
- Uncaught TypeError: props.users.map is not a function
- Immutable Data Structure - Application maintenance
- How to test Typescript class members in React with Jest
- Why doesnt the condition evaluate to false when not specifically checking for undefined value using react and typescript?
- How can I change border color for Select Component?
- React binding error: FontChooser.js:15 Uncaught TypeError: this.setstate is not a function
- extending default theme chakra ui
- React BrowserRouter Changes URL but Component doesn't Render
- How can I call a component in attribute of other component?
- Filtering through an API with Axio & React
- React, Redux: Loading data after navigate fails
- React, button with link and onClick
- React | Redux Toolkit Shared State Undefined
- create array for each same month in javascript
- MUI Chips as tags that can be selected (checkbox like behavior)
- How can I filter out a date between a range of date in a react-table
- React JS filter
- react-google-maps click the map to get coordinates
- Fetch request does not accept body but requests.get does
- How do I resolve the operation not permitted error while attempting to install react?
- React context consumer was rendered with multiple children error
- I want to modify what I receive by props
- Google ad units (DFP) shows number along with the ad on render. How should I hide that number?
- React ES6 alternative for mixins
- ReactJS: How can I play an html5 video with an onClick event correctly with react?
- TypeError: props... is not a function in reactjs