mirror of
https://github.com/penpot/penpot.git
synced 2025-02-18 21:06:11 -05:00
⚡ Add minor performance optimizations to code-block component
This commit is contained in:
parent
a44f2c5788
commit
1e9c809b84
1 changed files with 8 additions and 7 deletions
|
@ -9,12 +9,13 @@
|
||||||
["highlight.js" :as hljs]
|
["highlight.js" :as hljs]
|
||||||
[rumext.v2 :as mf]))
|
[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)]
|
(let [block-ref (mf/use-ref)]
|
||||||
(mf/use-effect
|
(mf/with-effect [code type]
|
||||||
(mf/deps code type block-ref)
|
(when-let [node (mf/ref-val block-ref)]
|
||||||
(fn []
|
(hljs/highlightElement node)))
|
||||||
(hljs/highlightElement (mf/ref-val block-ref))))
|
|
||||||
[:pre.code-display {:class type
|
[:pre.code-display {:class type :ref block-ref} code]))
|
||||||
:ref block-ref} code]))
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue