0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-02-13 10:38:13 -05:00

Add minor performance optimizations to code-block component

This commit is contained in:
Andrey Antukh 2023-07-20 12:05:06 +02:00
parent a44f2c5788
commit 1e9c809b84

View file

@ -9,12 +9,13 @@
["highlight.js" :as hljs]
[rumext.v2 :as mf]))
(mf/defc code-block [{:keys [code type]}]
(mf/defc code-block
{::mf/wrap-props false}
[{:keys [code type]}]
(let [block-ref (mf/use-ref)]
(mf/use-effect
(mf/deps code type block-ref)
(fn []
(hljs/highlightElement (mf/ref-val block-ref))))
[:pre.code-display {:class type
:ref block-ref} code]))
(mf/with-effect [code type]
(when-let [node (mf/ref-val block-ref)]
(hljs/highlightElement node)))
[:pre.code-display {:class type :ref block-ref} code]))