Fork me on GitHub
#reagent
<
2022-02-03
>
coetry21:02:51

How do we get fast refresh for reagent (preserving state while making changes to css or elements) + shadow-cljs

coetry21:02:10

currently, every time i make changes, my state resets

coetry21:02:22

also, I'm use hooks if that makes a difference

Richie03:02:28

I save state to local storage and then read it back out.

(defn ^:dev/before-load stop
  []
  (save-my-state @app-state))

(defn ^:dev/after-load start
  []
  (reset! app-state (read-my-state)))

coetry04:02:25

that's clever, but sounds more like a hack to me

Richie14:02:20

If I just defonce then the state persists across code changes. Is that what you want?

coetry19:02:24

ah i think that works, but i don't believe it works with hooks

Richie19:02:18

Oh, you’re saying you have hooks in shadow to build the css?

coetry19:02:28

sorry, i meant react hooks 🙂

coetry19:02:53

its taken for granted in modern React frameworks that your state gets preserved when making changes

coetry19:02:07

what's interesting is that inspiration for fast refresh arguably came from clojurescript world (figwheel), but seems like we've regressed as a community. defonce only works if you're using a central state atom

Richie19:02:11

I see, thanks I didn’t know for sure what you meant by “fast refresh”.

👍 1
coetry19:02:20

but not if you're doing react hooks for local component state

Richie20:02:08

I don’t have any state in my components so I don’t know how to help you with this.

Richie20:02:10

Interesting though.

coetry20:02:20

no problem, thanks for taking the time!

Richie20:02:33

You’re welcome.

coetry19:02:35

@UPD88PGNT thanks for going the extra mile to dig that up! It means a lot to me!

Richie19:02:23

I just happened across it and thought I should share. glhf!

❤️ 1
coetry05:02:19

I like to limit disk reads / writes if possible since I'm paranoid about preserving the life of SSDs and not hammering it if not necessary 😅 . It's probably OCD, but I really can't help think about that. I prefer sessions to remain in memory (faster as well) and only persisted when truly needed.

coetry05:02:34

but still cool, thanks for sharing!