Open genki opened 4 months ago
I'm not sure, this might be intended behavior to enable lazy-loading/lazy-execution.
May I ask what's your use case? You could use a signal instead:
import {
Signal,
component$,
useSignal,
useVisibleTask$,
} from '@builder.io/qwik';
type FooProps = {
testSig: Signal<number>;
};
const Foo = component$<FooProps>(({ testSig }) => {
// eslint-disable-next-line qwik/no-use-visible-task
useVisibleTask$(() => {
testSig.value = ++testSig.value;
});
return (
<>
<div>{testSig}</div>
</>
);
});
export default component$(() => {
const testSig = useSignal(2);
return (
<>
<Foo testSig={testSig} />
{/* I moved all logic to another file in-case you want to quickly delete and prototype something */}
<div style={{ padding: '1rem' }}>Hello World</div>
</>
);
});
@maiieul Yes, I understand this is intended. But I think it is better if warned before the run such as by the tsc or the linter.
Thanks @genki !
Yes I agree that it's a better DX if typescript or eslint could show an error in the code editor.
If anyone has experience with writing eslint rules and want to take a look at one of our existing rules to tackle this, go ahead! (or if @wmertens knows so some handy TS trick to make it happen, feel free to share 😊 )
So marking it as "PR is welcomed" for now, and we might tackle this after V2
Thanks again!
definitely use signals for this but yeah better lint/errors explaining why is a good idea and maybe we can suggest using signals.
what you want to do is either pass a signal or set the initial value of the signal to the prop value depending on what you're trying to do
@PatrickJS Yes, using the signal can avoid this :)
Which component is affected?
Qwik Runtime
Describe the bug
The props of the
component$
are given as the args of the QRL, so they should be mutable, but they are declared asconst
to be immutable through theuseLexicalScope
. This makes mismatch. So if I try to change the value of the args, it causesTypeError: Assignment to constant variable.
even if there's no error in compile time.Reproduction
https://stackblitz.com/edit/qwik-starter-c2m93t?file=src%2Froutes%2Findex.tsx
Steps to reproduce
Please see the link above.
System Info
Additional Information
No response