-
Notifications
You must be signed in to change notification settings - Fork 142
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to use "v-once" directive in JSX? #535
Comments
If you want to execute an event . You can try this <div onClickOnce = { your event }> content </div> |
@CrownHanhard |
Maybe like v-if, you can only do it in other ways For example, set a Watcheror initialize deep copy data |
@CrownHanhard, I don't think it works this way because: this <div v-once>
addadada
</div> compiles into this: import { setBlockTracking as _setBlockTracking, createTextVNode as _createTextVNode, createElementVNode as _createElementVNode } from "vue"
export function render(_ctx, _cache, $props, $setup, $data, $options) {
return _cache[0] || (
_setBlockTracking(-1),
_cache[0] = _createElementVNode("div", null, [
_createTextVNode(" addadada ")
]),
_setBlockTracking(1),
_cache[0]
)
} See here. |
🤔 |
Solution was right above me. Big bruh xD import { setBlockTracking as _setBlockTracking, createTextVNode as _createTextVNode, createElementVNode as _createElementVNode } from "vue"
export function render(_ctx, _cache, $props, $setup, $data, $options) {
return _cache[0] || (
_setBlockTracking(-1),
_cache[0] = _createElementVNode("div", null, [
_createTextVNode(" addadada ")
]),
_setBlockTracking(1),
_cache[0]
)
} |
Maybe it can help someone :) The first parameter of the import { defineComponent, ExtractPropTypes, withMemo } from 'vue';
const props = {
msg: String,
} as const;
export default defineComponent({
name: 'DisplayMsg',
props,
render(ctx: ExtractPropTypes<typeof props>, cache: unknown[]) {
return withMemo([/* ctx.msg */], () => <h1>{ctx.msg}</h1>, cache, 0);
},
}); I simplified to be able to call like this: const setup = (p: Props) => {
const memo = useMemo();
const msgMemo = memo(() => [p.msg]);
const msgOnceMemo = memo();
return {
msgMemo,
msgOnceMemo,
};
};
export default defineComponent({
name: 'DisplayMsgOnce',
props,
setup,
render(c: DisplayMsgOnce) {
const { msgMemo, msgOnceMemo } = c;
return (
<ul>
<li><small>v-once:</small> {msgOnceMemo(<span>{c.msg}</span>)}</li>
<li><small>v-memo:</small> {msgMemo(<span>{c.msg}</span>)}</li>
</ul>
);
},
}); |
|
Now, @vue-macros/jsx-directive@0.4.0 support // v-memo
<div
v-for={i in list}
v-memo={[selected === i]}
key={i}
onClick={() => (selected = i)}
>
{i}: {selected}
</div>
// v-once
<div v-once>{selected}</div> |
🧐 Problem Description
Do not understand how to use "v-once" directive with jsx?
💻 Sample code
🚑 Other information
When I try apply this directive I get error:
The text was updated successfully, but these errors were encountered: