Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to render children in Qwik?

Tags:

qwik

In React, I had this component:

const Title = ({ children }) => {
    return <h2>{children}</h2>
}

export default Title

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

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?

like image 758
Big boy Avatar asked Dec 01 '25 11:12

Big boy


1 Answers

Qwik uses Slot instead of children

import { component$, Slot } from '@builder.io/qwik'

const Title = component$(() => {
    return <h2><Slot /></h2>
})

export default Title

See https://qwik.builder.io/docs/components/projection/

like image 106
Daniel Tran Avatar answered Dec 05 '25 07:12

Daniel Tran



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!