简体   繁体   中英

How to make Redux update in a page-route component when revisiting it while Redux state doesn't change?

I only have my authentication in Redux to make it easier to get authentication and user data throughout the app, except for one page I decided to dispatch fetch some data from mongoDB with Redux (in a Home page).

When I go to another page, I make some modifications to the database. But when I come back to the Home page, it doesn't go fetch the data again, because nothing changed in it's state or props. Redux has it's own 'DidUpdate' so I can't force an update in the default React component lifecycle...

Is there a way to force the Home page (which uses Redux) to fetch DB data again when I go to that route (so that I can see the newly added DB data)?

Or am I stuck having to a) modify the Redux state from another page b) modify the React state of the parent of the Home component-page to trigger am update and fetch c) run my whole app through Redux so that any changes I make to the Redux store will trigger an update and call the fetching of data from the DB?

Thank you for any insights you can offer ;)

EDIT: Sorry, all good. I had a 'flawed' algorithm that checked if a recent fetch was done and wouldn't do another. All is ok now. Sorry for the bother.

So whenever you visit any page in React application, as per the life-cycle Componentdidmount() this function will get a trigger. So if you want to fetch new data from your API the just call you API URL of action Componentdidmount() .

  componentDidMount() {
    if (this.props.location) {// you can check your location as well.
      // call your API or function which will call your API
    }
  }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM