Git Product home page Git Product logo

Comments (7)

japgolly avatar japgolly commented on July 4, 2024

Yeah I believe that's already possible. I think the type you're looking for is VDom. Does that work for you?

from scalajs-react.

artursoler avatar artursoler commented on July 4, 2024

You are right, I can pass both a Component() and a div(Component()) as a VDom.

Unfortunately I can't pass the resulting VDom to another tag, such as div(myVDom). I get the following error:

[error] found : japgolly.scalajs.react.VDom
[error] required: japgolly.scalajs.react.vdom.ReactVDom.Modifier

from scalajs-react.

japgolly avatar japgolly commented on July 4, 2024

Maybe I misunderstood (or even gave you wrong info re VDom), is this the kind of thing you're trying to do?

https://github.com/japgolly/scalajs-react/blob/master/example/src/main/scala/japgolly/scalajs/react/example/ReactExamples.scala#L83-L85

https://github.com/japgolly/scalajs-react/blob/master/test/src/test/scala/japgolly/scalajs/react/CoreTest.scala#L112-L127

If not, are you able to show me a bit of the code?

from scalajs-react.

artursoler avatar artursoler commented on July 4, 2024

I can put components inside div/span/etc without problems if it's directly. I can't put elements of type "VDom" inside div/span/etc.

I've created a toy example to show the issue. Let's create a component that gets something that can be rendered and renders it twice.

  object Duplicate {
    def apply(element: VDom) = ReactComponentB[Unit]("Duplicate")
      .render { props =>
        div(element, element)
      }
      .create(())
  }

This produces the same compile error as before:

[error]  found   : japgolly.scalajs.react.VDom
[error]  required: japgolly.scalajs.react.vdom.ReactVDom.Modifier
[error]     (which expands to)  scalatags.generic.Modifier[japgolly.scalajs.react.vdom.VDomBuilder]
[error]         div(element, element)

from scalajs-react.

japgolly avatar japgolly commented on July 4, 2024

Ah sorry Artur, I gave you the wrong information - I'm always forgetting the Scalatags types and the way I integrated a bit of that. You want Modifier. I'll make a note to simplify these types soon.

  object Duplicate {
    def apply(element: Modifier) = ReactComponentB[Unit]("Duplicate")
      .render { props =>
      div(element, element)
    }.create(())

    apply(h1("hello"))

    val HelloMessage = ReactComponentB[String]("HelloMessage")
      .render(name => div("Hello ", name))
      .build.apply("hehe")

    apply(HelloMessage)
  }

from scalajs-react.

artursoler avatar artursoler commented on July 4, 2024

Works great, thanks!!!

from scalajs-react.

japgolly avatar japgolly commented on July 4, 2024

Great to hear. Enjoy!

from scalajs-react.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.