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:
parent
a44f2c5788
commit
1e9c809b84
1 changed files with 8 additions and 7 deletions
|
@ -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]))
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue