Props is a mechanism by which components communicate with each other.
Imagine a situation where the parent <MyApp>
component needs to pass information to a child's <Greeter>` component. (Here is a code example)
import { qComponent, qHook } from '@builder.io/qwik';
export const MyApp = qComponent({
onRender: qHook(() => (
<div>
<Greeter name="World" />
</div>
)),
});
export const Greeter = qComponent<{ salutation?: string; name?: string }>({
onRender: qHook((props) => (
<span>
{props.salutation || 'Hello'} <b>{props.name || 'World'}</b>
</span>
)),
});
In the above example, <Greeter>
component declares its props to be { salutation?: string; name?: string }
. You can think of the props as the inputs of the component.
An essential property of Qwik is that components can be rehydrated out-of-order. There are several implications:
To perform the above responsibilities, Qwik provides qProp
primitive.
qProp
qProp
's job is to provide props to the component and hide all of the complexity of object serialization/deserialization and object reference tracking. The best way to think about qProp
is as a wrapper around DOM element.
const div = document.createElement('div');
// <div/>
const qDiv = qProps(div);
qDiv.name = 'World';
// <div name="World">
qDiv.planet = { name: 'Earth', age: '4p6bn' };
// <div name="World" planet="*abc123" q:obj="abc123">
// New object with id 'abc123' has been created
const span = document.createElement('span');
const qSpan = qProps(span);
qSpan.foo = qDiv.planet;
// <div name="World" planet="*abc123" q:obj="abc123">
// <span planet="*abc123" q:obj="abc123">
// Notice that the same object ID is used for both.
Usually, the framework invokes qProp
on the developer's behalf, and there is no need to invoke the API directly in the application code. It is useful to invoke the API in tests as well as when debugging the application in DevTools to understand what is going on.
or
or
By clicking below, you agree to our terms of service.
New to HackMD? Sign up
Syntax | Example | Reference | |
---|---|---|---|
# Header | Header | 基本排版 | |
- Unordered List |
|
||
1. Ordered List |
|
||
- [ ] Todo List |
|
||
> Blockquote | Blockquote |
||
**Bold font** | Bold font | ||
*Italics font* | Italics font | ||
~~Strikethrough~~ | |||
19^th^ | 19th | ||
H~2~O | H2O | ||
++Inserted text++ | Inserted text | ||
==Marked text== | Marked text | ||
[link text](https:// "title") | Link | ||
 | Image | ||
`Code` | Code |
在筆記中貼入程式碼 | |
```javascript var i = 0; ``` |
|
||
:smile: | ![]() |
Emoji list | |
{%youtube youtube_id %} | Externals | ||
$L^aT_eX$ | LaTeX | ||
:::info This is a alert area. ::: |
This is a alert area. |
On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?
Please give us some advice and help us improve HackMD.
Do you want to remove this version name and description?
Syncing