You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I've got an empty store on componentDidMount so I can't render data on component loading. As I can see via logs store hydrated just after the component was mounted.
I've tried to implement solution from #38 on my root component (App.js) but if user not on index page then componentDidMount with hydration didn't trigger.
import{store}from'../../state';importHeaderfrom'../header';importFooterfrom'../footer';importErrorBoundryfrom'../error-boundry';import'./app.css';importMainPagefrom'../main-page';importLoginPagefrom'../login-page';importAccountPagefrom'../account-page';import{create}from'mobx-persist';consthydrate=create({storage: localStorage,jsonify: true,});
@observerclassAppextendsComponent{asynccomponentDidMount(){awaithydrate('store',store);console.log('Mounted index page');}SearchPage=()=><h2>Search Page</h2>;AddListingPage=()=><h2>Add Listing Page</h2>;render(){return(<Providerstore={store}><ErrorBoundry><Router><divclassName="app-container"><Header/><divclassName="content-wrapper"><Routepath="/"exactcomponent={MainPage}/><Routepath="/search"component={this.SearchPage}/><Routepath="/account"component={AccountPage}/><Routepath="/login"component={LoginPage}/><Routepath="/add-listing"component={this.AddListingPage}/></div><Footer/></div></Router></ErrorBoundry></Provider>);}}
For example, in AccountPage store is empty on componentDidMount. Only way I can check if user logged-in is adding check to componentDidUpdate.
Hey, I had a similar issue, where my APIs were getting called from cDM while the hydration was not complete. hence some empty headers and params were being passed. So what I did was, I created a component called PersistStore that had the responsibility of hydrating all my stores and after all of them were hydrated only then I would render my main app. Here is the code.
I've got an empty store on componentDidMount so I can't render data on component loading. As I can see via logs store hydrated just after the component was mounted.
I've tried to implement solution from #38 on my root component (App.js) but if user not on index page then componentDidMount with hydration didn't trigger.
For example, in
AccountPage
store is empty oncomponentDidMount
. Only way I can check if user logged-in is adding check tocomponentDidUpdate
.Any suggestions on how to get a hydrated store before component will be mounted on any page? I'm using
react-router
The text was updated successfully, but these errors were encountered: