Issue
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))
Solution
Perhaps you are looking for the on
helper?
createEffect(
on(
() => location.pathname,
() => setShowMenu(false)
)
);
https://www.solidjs.com/docs/latest/api#on
Answered By - FoolsWisdom
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.