Derived value in event handler causing router error

Error: Make sure your app is wrapped in a <Router /> when calling an eventhandler. Just trying to log a derived signal/prop in my buy function. The values from product() get printed correctly in my DOM
const product = () => props.product
const [qty, setQty] = createSignal(0)

function buy() {
console.log(product())
// console.log(qty())
}
const product = () => props.product
const [qty, setQty] = createSignal(0)

function buy() {
console.log(product())
// console.log(qty())
}
The second console.log works fine. But the first throws
Uncaught Error: Make sure your app is wrapped in a <Router />
at invariant (utils.js?v=8381e9f0:28:15)
at useRouter (routing.js?v=8381e9f0:9:32)
at useRoute (routing.js?v=8381e9f0:11:75)
at useParams (routing.js?v=8381e9f0:37:32)
at product (ProductDetail.tsx:11:22)
Uncaught Error: Make sure your app is wrapped in a <Router />
at invariant (utils.js?v=8381e9f0:28:15)
at useRouter (routing.js?v=8381e9f0:9:32)
at useRoute (routing.js?v=8381e9f0:11:75)
at useParams (routing.js?v=8381e9f0:37:32)
at product (ProductDetail.tsx:11:22)
7 Replies
uchiha_savior
uchiha_saviorOP2y ago
Ok so wrapping it in createMemo fixed it. const product = createMemo(() => props.product). Is this the correct way to do this?
jesseb34r
jesseb34r2y ago
i don't understand the reason for the error so I can't help with that but why do you need a derived signal for that? why not just use props?
uchiha_savior
uchiha_saviorOP2y ago
dont wanna do props.product everywhere, sort of alternate to props destructuring
jesseb34r
jesseb34r2y ago
doing props.* everywhere is how Solid intends props to be used. If you prefer destructuring, you could always check out the solid primitive for that https://primitives.solidjs.community/package/destructure#spread-component-props
Solid Primitives
A library of high-quality primitives that extend SolidJS reactivity
jesseb34r
jesseb34r2y ago
@uchiha_savior
uchiha_savior
uchiha_saviorOP2y ago
I'll check it out. Thanks
Braveheart
Braveheart2y ago
i also see this from time to time, clearing nod mods seems to help sometimes
Want results from more Discord servers?
Add your server