effector-storage: Effector Next does not update persisted value
After migrating to Effector 23 and effector-store 7, the persisted value in my store is not updating correctly. Here is the relevant code:
import { persist } from "effector-storage/session";
interface bannerDownloadTopStore {
open: boolean;
}
export const openBannerDownloadTop = createEvent();
export const closeBannerDownloadTop = createEvent();
export const $bannerDownloadTop = createStore<bannerDownloadTopStore>(
{ open: false },
{ sid: "bannerDownloadTop" }
)
.on(openBannerDownloadTop, (state) => ({ ...state, open: true }))
.on(closeBannerDownloadTop, (state) => ({ ...state, open: false }));
const changeBannerDownloadTopClosed = createEvent();
export const $bannerDownloadTopClosed = createStore<boolean>(false, {
sid: "bannerDownloadTopClosed",
}).on(changeBannerDownloadTopClosed, (_state, payload) => payload);
sample({
clock: closeBannerDownloadTop,
fn: () => true,
target: changeBannerDownloadTopClosed,
});
persist({ store: $bannerDownloadTopClosed, key: "bannerDownloadTopClosed" });
export const BannerDownloadTop: React.FC = () => {
const { open: isOpen } = useUnit($bannerDownloadTop);
const wasClosed = useUnit($bannerDownloadTopClosed); //false
The issue is that wasClosed always remains false, even though $bannerDownloadTopClosed.watch logs the correct value (true):
$bannerDownloadTopClosed.watch((store) =>
console.log(333, "$bannerDownloadTopClosed", store) //true
);
It seems that the persisted value is not being updated properly after the migration. Could you help me resolve this issue?
"effector": "^23.3.0",
"effector-react": "^23.3.0",
"effector-storage": "^7.1.0",```
sessionStorage.getItem('bannerDownloadTopClosed') //true
About this issue
- Original URL
- State: open
- Created 2 years ago
- Comments: 16 (9 by maintainers)
@yumauri https://github.com/AndreyOsipuk/test-effector-next. Can I use this logic in
_app.tsx?If you can create a small repository demonstrating the issue, I can investigate it. Based on the
@effector/nextdocumentation, it might be possible to usegetClientScopefunction, perhaps something like this: