In React, I had this component:
const Title = ({ children }) => {
return <h2>{children}</h2>
}
export default Title
Run Code Online (Sandbox Code Playgroud)
And I could easily use it as <Title>Something</Title>
In Qwik, I can create the same component:
import { component$ } from '@builder.io/qwik'
const Title = component$(({ children }) => {
return <h2>{children}</h2>
})
export default Title
Run Code Online (Sandbox Code Playgroud)
But <Title>Something</Title> does not work. Even <Title children='Something' /> does not work. But if I change the prop name to text, then <Title text='Something' /> works.
However, the ability to nest components and reuse them under a special name is a must in real-world applications.
How can I render children in Qwik?
Qwik 使用 Slot 代替孩子
import { component$, Slot } from '@builder.io/qwik'
const Title = component$(() => {
return <h2><Slot /></h2>
})
export default Title
Run Code Online (Sandbox Code Playgroud)
请参阅https://qwik.builder.io/docs/components/projection/
| 归档时间: |
|
| 查看次数: |
421 次 |
| 最近记录: |