[英]Reagent doesn't rerender component with deref-ing inside of let
I have atom foo
: 我有原子
foo
:
(defonce foo (r/atom "foo"))
I have parent component: 我有父组件:
(defn parent-component []
(js/setTimeout #(reset! foo "bar") 5000)
(child-component {:foo foo}))
And I have child component: 我有孩子组成部分:
(defn child-component [props]
(let [derefed (deref (:foo props))]
(fn []
[:div
[:p derefed]
[:p (deref (:foo props))]])))
Only second paragraph is updated after reseting foo
. 重置
foo
后只更新第二段。
Why is it working that way? 为什么这样工作?
From the re-frame documentation regarding Form-2 components: https://github.com/Day8/re-frame/wiki/Creating-Reagent-Components#form-2--a-function-returning-a-function . 从有关Form-2组件的重新框架文档: https : //github.com/Day8/re-frame/wiki/Creating-Reagent-Components#form-2--a-function-returning-a-function 。
You need to repeat the outer function parameters again in the inner function: 您需要在内部函数中再次重复外部函数参数:
(defn child-component [props]
(fn [props]
(let [derefed (deref (:foo props))]
[:div
[:p derefed]
[:p (deref (:foo props))]])))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.