Menu

Both of our persisted stores filter what they load off the phone, and one filter is why a picker cannot crash
📰

Both of our persisted stores filter what they load off the phone, and one filter is why a picker cannot crash

DEV Community: reactnative·Daniel Pertu·12 days ago
#9ZertyDs
#devtoreactnative#devto#dev#array#filter
Long article (1276 words) — no AI summary yet.
Reading 0:00
15s threshold

Munchable keeps the health part of its state on the device, so a returning user's profile and scan history come off local storage rather than out of a database. Which means the app reads data written by a build of itself that no longer exists, and has to decide what to do with the parts it no longer recognises.

Six stores in the app, and only two of them survive a relaunch: the dietary profile and the history. Both of them override zustand's merge , and both of them throw data away.

The profile drops ids this build does not know

The profile holds three arrays of ids: the conditions you are eating for, the allergies you asked to be warned about, and the things you would rather not buy. All three are re-validated on the way in:

merge : ( persisted , current ) => { const p = ( persisted ?? { } ) as Partial < ProfileState > ; return { . . . current , . . . p , conditions : Array . isArray ( p . conditions ) ? p . conditions . filter ( isConditionId ) : [ ] , allergens : Array . isArray ( p . allergens ) ?…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.