Closed SomervilleTom closed 9 months ago
Hi! Sorry for the very late response. I'm finally doing some updates on the example app and saw this.
This is expected behavior. A Redux store is like any other JS variable - it only exists for the lifetime of this page. When you reload the page, an entire new JS environment is created from scratch, including a new Redux store.
This example app is configured to generate some initial fake data, but it doesn't do anything to persist items you might have added while using the example app.
So yes, reloading the page will throw away all of the new items you added - that's fully expected.
This issue appears to be similar to Issue #64.
I'm using the
tutorial-steps
branch of the tutorial, and I exercised the app immediately after addingSinglePostPage
.I had to make several modifications to 'package.json' in order to make the app run, as follows:
msw
to require "^0.38.0"react-scripts
to require "^5", copy a patched 'getHttpsConfig.js' into
react-scripts/config/`yarn install
, run 'npx msw init public' from the project directoryWith these changes in place, I think performed the tutorial steps to:
SinglePostPage
App.js
as per the tutorialPostsList.js
as per the tutorialNavbar.js
as per the tutorialThe third post appears in the app:
I then clicked reload in the (Chrome) browser. This causes the added post to be dropped:
I see similar behavior in `PostsList'. Immediately after clicking "Save Post", I see the added post:
After reload, the added post disappears:
I used breakpoints in the
dispatch
call topostAdded
inSinglePostForm
andpostsSlice
, and it appears that the value ofstate
-- presumably coming fromProvider
-- is reset to its initial state after a refresh.Sadly, I don't have the expertise to determine whether this is a bug in the tutorial, in
@reduxjs/toolkit
, or in redux itself.I appreciate any guidance or workaround for ensuring that the app I'm building will behave as expected after a reload.