From 757b8ebcac82f8514e86eb219d3eddd05882ed63 Mon Sep 17 00:00:00 2001 From: Sean Hagstrom Date: Mon, 1 Apr 2024 18:28:50 +0100 Subject: [PATCH] tweak: utilise use-layout-effect to safely update atom --- .../profile/contact/contact_request/view.cljs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/status_im/contexts/profile/contact/contact_request/view.cljs b/src/status_im/contexts/profile/contact/contact_request/view.cljs index c9f9c0cdc4..877c6411f8 100644 --- a/src/status_im/contexts/profile/contact/contact_request/view.cljs +++ b/src/status_im/contexts/profile/contact/contact_request/view.cljs @@ -92,12 +92,18 @@ (defn make-snapshot-handler-factory [snapshot] (let [storage (rn/use-memo #(atom {}) []) capture (rn/use-memo #(atom snapshot) []) + _update (rn/use-layout-effect + (fn [] + (swap! capture (fn [_] snapshot))) + snapshot) factory (rn/use-memo - (do (swap! capture (fn [_] snapshot)) - #(memo storage + (fn [] + (fn [handler] + ((memo storage (fn [callback] (fn [event] - (callback @capture event))))) + (callback @capture event)))) + handler))) [storage capture])] {:factory factory :storage storage}))