Skip to content

Commit 58b77d9

Browse files
committed
Add Vdom{Tag,Element}.renderIntoDOM
1 parent 8ae29d3 commit 58b77d9

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

core/src/main/scala/japgolly/scalajs/react/vdom/ReactVdom.scala

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package japgolly.scalajs.react.vdom
22

3-
import japgolly.scalajs.react.{raw => Raw}
3+
import japgolly.scalajs.react.{Callback, raw => Raw}
44
import scala.scalajs.js
55

66
sealed class VdomNode(val rawNode: Raw.ReactNode) extends TagMod {
@@ -18,7 +18,10 @@ object VdomNode {
1818

1919
// =====================================================================================================================
2020

21-
final class VdomElement(val rawElement: Raw.ReactElement) extends VdomNode(rawElement)
21+
final class VdomElement(val rawElement: Raw.ReactElement) extends VdomNode(rawElement) {
22+
def renderIntoDOM(container: Raw.ReactDOM.Container, callback: Callback = Callback.empty): Raw.ReactComponentUntyped =
23+
Raw.ReactDOM.render(rawElement, container, callback.toJsFn)
24+
}
2225

2326
object VdomElement {
2427
def apply(n: Raw.ReactElement): VdomElement =

core/src/main/scala/japgolly/scalajs/react/vdom/Tag.scala

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package japgolly.scalajs.react.vdom
22

3+
import japgolly.scalajs.react.{Callback, raw => Raw}
4+
35
class TagOf[+N <: TopNode] private[vdom](final val tag: String,
46
final protected val modifiers: List[Seq[TagMod]],
57
final val namespace: Namespace) extends TagMod {
@@ -53,6 +55,9 @@ class TagOf[+N <: TopNode] private[vdom](final val tag: String,
5355

5456
override def applyTo(b: Builder): Unit =
5557
b.appendChild(render.rawElement)
58+
59+
def renderIntoDOM(container: Raw.ReactDOM.Container, callback: Callback = Callback.empty) =
60+
render.renderIntoDOM(container, callback)
5661
}
5762

5863
// =====================================================================================================================

doc/changelog/1.1.0.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
* `vdom.TagMod` now has a `.toJs` method which turns the VDOM tree into a bunch of raw JS values.
1717
This is for advanced hackers only.
1818

19+
* Add `.renderIntoDOM` to `VdomElement` and `VdomTag`s.
20+
1921
* Opening links in new tabs using `target="_blank"` without `rel="noopener` is a
2022
[security risk and performance impediment](https://blog.dareboost.com/en/2017/03/target-blank-links-rel-noopener-performance-security/).
2123
Google's Lighthouse auditor [flags it](https://developers.google.com/web/tools/lighthouse/audits/noopener).

0 commit comments

Comments
 (0)