Skip to content

Commit aec77c1

Browse files
authored
docs: add dot notation guide (#8236)
1 parent e21f93b commit aec77c1

File tree

1 file changed

+52
-0
lines changed
  • packages/docs/src/routes/docs/(qwik)/core/overview

1 file changed

+52
-0
lines changed

packages/docs/src/routes/docs/(qwik)/core/overview/index.mdx

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,58 @@ const Child = component$(() => {
9090

9191
> Notice that Qwik components are already lazy loaded thanks to the `$` sign. That means that you don't need to dynamically import the child component manually, Qwik will do it for you.
9292
93+
### Dot Notation Components
94+
95+
While you cannot directly attach properties to a component created with `component$` (e.g. `Scene.Title = Title`), you can achieve dot-notation by using ES module exports or barrel files.
96+
97+
#### Using Barrel Files
98+
99+
Create an `index.ts` file in your component directory to group related components:
100+
101+
```tsx
102+
// components/scene/index.ts
103+
export { SceneComponent as Root } from './scene-root';
104+
export { SceneTitle as Title } from './scene-title';
105+
```
106+
107+
Then, you can import and use them with dot notation:
108+
109+
```tsx
110+
import * as Scene from './components/scene';
111+
112+
export default component$(() => {
113+
return (
114+
<Scene.Root>
115+
<Scene.Title>ACT III Scene II</Scene.Title>
116+
</Scene.Root>
117+
);
118+
});
119+
```
120+
121+
#### Exporting as Namespace
122+
123+
You can also export all sub-components from a directory as a single namespace:
124+
125+
```tsx
126+
// components/ui/index.ts
127+
export * as Select from './select';
128+
export * as Accordion from './accordion';
129+
```
130+
131+
And use it like so:
132+
133+
```tsx
134+
import { Select } from './components/ui';
135+
136+
export default component$(() => {
137+
return (
138+
<Select.Root>
139+
<Select.Item>Option 1</Select.Item>
140+
</Select.Root>
141+
);
142+
});
143+
```
144+
93145
### Counter Example
94146

95147
A slightly more complex example of a counter.

0 commit comments

Comments
 (0)