Comments (7)
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.
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.
Maybe I misunderstood (or even gave you wrong info re VDom
), is this the kind of thing you're trying to do?
If not, are you able to show me a bit of the code?
from scalajs-react.
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.
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.
Works great, thanks!!!
from scalajs-react.
Great to hear. Enjoy!
from scalajs-react.
Related Issues (20)
- Export `assertOuterHTML` HOT 1
- Deprecate `Mounted` component types HOT 2
- Add default arg to `ReactTestUtils.withRendered` HOT 1
- ScalaFnComponent is anonymous HOT 2
- Consider using `DocumentFragments` in `ReactTestUtils` HOT 1
- Re-evaluate `ComponentDom` post- React 18
- Is there a way to integrate Components with cats.effect.Ref? HOT 1
- Ref not always set HOT 2
- Syntax to integrate `useContext` with context function in Scala 3 HOT 1
- Compilation fails in Scala 3 when deriving Reusability for case classes with multiple parameter groups HOT 1
- Missing getDerivedStateFromError
- Missing / misspelled packages in MODULES.md HOT 1
- Add support for Discussions tab in Github HOT 1
- Modern testing recipe?
- Cannot mix static and dynamic routes even if conditional
- A minimal setup fails with Scala 3 HOT 5
- Provide default IO/SyncIO error handler for component
- ScalaFnComponent doesn't include displayName HOT 1
- Another way to define hook components
- AsyncCallback + cats, gracefully handling errors with EitherT: unexpected behaviour HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from scalajs-react.