-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
[🐞] args of the component$
are not mutable.
#6423
Comments
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. |
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! 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 |
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 causes
TypeError: 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
The text was updated successfully, but these errors were encountered: