There is a DeliveryManifestView component. It runs an effect which dispatches a thunk.
The thunk gets data from the api, then it is normalized with normalizr
.
The normalizedData
is passed to an action created by redux-toolkit
.
And the reducer returns the new object of the entity.
It works perfectly on the first run. However if I go to another view then come back
the effect re-runs, the thunk is dispatched,
the data comes from the api,
the data passed to the reducer again and the reducer returns the new data,
but no changes happen in state, I still get the old state.
Here is the action diff from redux devtools
This is on the very first render
After going back to another view and coming back
No diff in data reducer, even though a new data came from the api.
The problem was that when normalizr gets an empty array it returns an undefined
and so reducer returned undefined
as well resulting in no changes. Here is the solution I came up with
giving a default value to the deliveryPackages
.