FelipeEmos
Explore posts from serversHow to trigger createEffect when navigating to the same URL ?
Nice, this seems pretty decent
The "run too much" aspect of it is probaby negligible and you shouldn't be too worried about edge cases in my opinion
If this starts giving you some problems or you want to be extra careful about such "edge cases", you can always do a diffing yourself! That should be easy, you have to track the last time you've run the effect and do an early exit if necessary.
Maybe save the "lastUrl" in a variable and if the current "url" is equal to the "lastUrl" do nothing, just early exit. Then if it changed you update the "lastUrl" and do your computation 🚀
9 replies
How to trigger createEffect when navigating to the same URL ?
I don't think it's worth it to go for the "navigate just to retrigger" thing as you suggested last.... I agree it's not clean, a little hacky
If you wanted to solve things in a similar "not ideal" solution you could put a manual reset trigger on your specific action that is troublesome. Here's a code ChatGPT created when I prompted our conversation
It makes sense
9 replies
How to trigger createEffect when navigating to the same URL ?
Your question has an interesting phrasing... what you do you want to do with that possibility?
Maybe you should look at the problem at a different angle... so what's your problem?
Have you considered something like just putting an even listener to whenever the router changes routes?
9 replies