Skip to content

Latest commit

 

History

History
31 lines (21 loc) · 1.02 KB

File metadata and controls

31 lines (21 loc) · 1.02 KB

Custom Virtual DOM Example

If you want to customize VirtualDOM, you can create your own VirtualDOM.

For example, say you didn't like using < and ^ to access tags and attributes, and you wanted to use E and A instead.

First, create your own VirtualDOM:

package io.github.shogowada.scalajs.reactjs.example.customvirtualdom

import io.github.shogowada.scalajs.reactjs.VirtualDOM

object CustomVirtualDOM extends VirtualDOM {
  lazy val E = <
  lazy val A = ^
}

Then, import the customized version of VirtualDOM:

import io.github.shogowada.scalajs.reactjs.elements.ReactElement
import io.github.shogowada.scalajs.reactjs.example.customvirtualdom.CustomVirtualDOM._

object HelloWorld {
  def apply(): ReactElement = E.div(A.id := "hello-world")("Hello, World!")
}

VirtualDOM is just an extension of StaticTags. If you are interested in customizing VirtualDOM more, please read StaticTags documentation.