Is there a way to trigger Solid's createEffect
using an external dependency, as with React's useEffect
dependency array?
I want to call setShowMenu
on location.pathname
change.
const location = useLocation()
createEffect(() => {
console.log(location.pathname) // << external dependency
setShowMenu(false)
})
Until there's a better option, I'm using this as a workaround.
const location = useLocation()
createEffect(() => location.pathname && setShowMenu(false))
Perhaps you are looking for the on
helper?
createEffect(
on(
() => location.pathname,
() => setShowMenu(false)
)
);