Replies: 1 comment 1 reply
|
I checked, and your export function StoreProvider({ children, initialState: initialData }) {
const store = initializeStore(initialData);
return <StoreContext.Provider value={store}>{children}</StoreContext.Provider>;
}
The fix is to memoize so import { useState } from "react";
export function StoreProvider({ children, initialState: initialData }) {
const [store] = useState(() => initializeStore(initialData));
return <StoreContext.Provider value={store}>{children}</StoreContext.Provider>;
}
|
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
I have a similar implementation of mobx with next js:
_app.tsxStoreProvider.tsxstore.tsssr.tsx// pagePage ComponentI am making an API call in getServerSideProps in ssr page which hydrates the store with initial data.
I have a use case where i have to update the api data in client based on user interaction sort of like a filter.
I make an api call on button interaction and update the store with updated data.
Problem:
The problem arises when i integrate query params to store the filters.
As soon as i update the query params with router push shallow true.
The _app.js re-renders with the stale data from server and updates the store with stale data.
What should happen:
When we update query params.
The store should not be updated with the initial data from server which overrides the updated data.
My main use case is pagination and filtering of data and i want to keep the state of filters and page in query params.
All reactions