Fork me on GitHub
#fulcro
<
2022-01-14
>
Declan14:01:04

Hi I'm struggling with persisting state in localstorage but I'm not even sure I should be trying to do this. To be clear - I can read and write to localstorage no problem. What I want is to have some control over the behaviour of the app if the page is refreshed or a copy opened in a new tab / window In previous React apps I've used redux-persist to keep a local copy of state, which makes this relatively seamless Redux-persist also allowed me to have white-lists and black-lists so I could control what was actually added to localstorage .. I've looked at browser-edn-store but that wants me to save using specific keys (which may be the way to go) .. other threads suggest transit-clj->str but even with a very modest/small state I'm getting write errors (even with {metadata? false} ) Any steers or thoughts would be most welcome - thanks

Jakub Holý (HolyJak)21:01:56

The state should be serializable. That's how it gets from the app into Fulcro Inspect - see https://github.com/fulcrologic/fulcro/blob/develop/src/main/com/fulcrologic/fulcro/inspect/transit.cljs

👀 1
Jakub Holý (HolyJak)21:01:31

Personally, I'd go with com.fulcrologic.fulcro.offline.browser-edn-store because I trust Tony :)

Declan19:01:19

Short answer is I basically got this working I think my initial problems were related to not fully understanding the code / examples In essence I think transit-clj->str was being called twice, once manually by me and then inside browser-edn-store so by removing my manual step it seems to work Thanks again for your input as it certainly helped me to look at the problem in a different way and finally figure it out

🎉 1