A minimalistic ClojureScript interface to React.js
wombawomba 2021-04-07T00:16:44.089600Z

I store it in an atom 🙂

wombawomba 2021-04-07T00:17:16.089800Z

I use plain reagent for 'intra-component' state

wombawomba 2021-04-07T00:18:34.090Z

and yeah as it turns out, that's the problem

wombawomba 2021-04-07T00:19:04.090200Z

reagent doesn't reset *info when I reload

wombawomba 2021-04-07T00:20:33.090500Z

I had the same problem with the error-boundary component you proposed, because it also keeps state in an atom

wombawomba 2021-04-07T00:42:46.090800Z

I'm honestly kind of stumped as to how I should approach this

wombawomba 2021-04-07T00:43:44.091Z

basically the call order seems to be 1. get-derived-state-from-error 2. render 3. component-did-catch

wombawomba 2021-04-07T00:44:23.091200Z

I want to use the info arg, that's only provided to component-did-catch to trigger a re-render (so I can display that state)

wombawomba 2021-04-07T00:45:02.091500Z

is there a way to do this without wrapping the component in (let [*info (r/atom nil)] )?

wombawomba 2021-04-07T00:45:30.091700Z

alternatively, is there a way to force that atom to be cleared when the page gets reloaded?

wombawomba 2021-04-07T01:11:31.091900Z

....okay, I finally got it working the way I want

wombawomba 2021-04-07T01:11:40.092100Z

(defn <error-boundary>
  "Util for inserting an error boundaries in the React tree. When a child throws
  an error, just renders that error instead of crashing."
  [& _]
  (let [*error (atom nil)]
     {:component-did-catch          (fn [this e i]
                                      (reset! *error [e (.-componentStack i)])
                                      (.forceUpdate this))
      :display-name                 "error-boundary"
      :get-derived-state-from-error #(reset! *error [%])
      :render                       #(r/as-element
                                      (if-let [[error stack] @*error]
                                        [<error-message> error stack]
                                        (into [:<>] (r/children %))))})))

wombawomba 2021-04-07T01:11:55.092300Z

plain old non-reagent atoms (and forceUpdate) to the rescue 🙂

p-himik 2021-04-07T08:38:53.093100Z

Nice! Yeah, now reading your messages, I realize that I probably have the same problem. And it's just that I've added an "Undo" button to the re-frame app specifically to undo whatever action has led to the error that prevented me from noticing it.