S
SolidJS5mo ago
_JS

Imported unused variable for a directive seems awkward

I've went through the SolidJS tutorial (https://www.solidjs.com/tutorial/bindings_directives?solved) and saw that the imported directive function is just "hanging" there. I understand the bindings and directives are just syntactic sugar and behind the scenes its actually not "hanging". I was wondering if this is something that I should care about, should I be worried or is this going to be something that I should get used to? Preferably I'd be happy with something other than true && insertDirectiveFunctionName to get around it. Thank you for reading, any feedbacks are much appreciated!
SolidJS
Solid is a purely reactive library. It was designed from the ground up with a reactive core. It's influenced by reactive principles developed by previous libraries.
4 Replies
lxsmnsyc
lxsmnsyc5mo ago
we usually do myDirective; somewhere ideally on the component that uses it e.g.
function Example() {
myDirective;
return <div use:myDirective/>;
}
function Example() {
myDirective;
return <div use:myDirective/>;
}
_JS
_JS5mo ago
Ah, I seee. If you may, what does that compile down to?
lxsmnsyc
lxsmnsyc5mo ago
for the question of "should you be worried", some bundlers kinda remove the unused import as part of the DCE process, mistakenly. Not sure which bundlers behave this way but it has been reported numerous times
function Example() {
myDirective;
return (() => {
const el = tmpl.cloneNode(true);
myDirective(el);
return el;
})();
}
function Example() {
myDirective;
return (() => {
const el = tmpl.cloneNode(true);
myDirective(el);
return el;
})();
}
pardon if it's inaccurate I'm typing on a phone lol
_JS
_JS5mo ago
Hey man, that's a lot of effort and I appreciate you writing such detailed answer I'm using SolidStart, so far it hasn't removed my unused import in dev mode. I'll go with your approach
Want results from more Discord servers?
Add your server
More Posts