S
SolidJS6d ago
xxttt

hook

Can I destructure my hook in SolidJS? It returns values via an anonymous function and doesn't lose reactivity. Is it bad?
1 Reply
bigmistqke
bigmistqke6d ago
depends on the implementation const [signal, setSignal] = createSignal() is also a destructuring this type of code would not reactively update on updates to signal:
function createHook(){
const [signal, setSignal] = createSignal()
return {
get value(){
return signal()
}
}
}
function Component(){
const { value } = createHook()
console.log(value)
}
function createHook(){
const [signal, setSignal] = createSignal()
return {
get value(){
return signal()
}
}
}
function Component(){
const { value } = createHook()
console.log(value)
}
as long as you keep in mind that the component will never re-run, you should be fine.
Want results from more Discord servers?
Add your server