composition-api icon indicating copy to clipboard operation
composition-api copied to clipboard

fix: useAsync runing server and client at the same time

Open angularBBB opened this issue 3 years ago • 2 comments

🐛 The bug What isn't working? Describe what the bug is.

🛠️ To reproduce Steps to reproduce the behavior: image

image

I use vue2.7 in setup use "useAsync" it being executed in server and client

🌈 Expected behaviour useAsync only executed in server or client

ℹ️ Additional context https://github.com/szptWangrs/nuxt-template.git

angularBBB avatar Jul 14 '22 11:07 angularBBB

useAsync is meant to return a value. If no value is returned it will run it again.

danielroe avatar Sep 14 '22 08:09 danielroe

@danielroe so useFetch cant be used to dispatch vuex calls, and useAsync cant be used to dispatch vuex calls ( as they store into state and not used directly retunred values usually). What left then?

aldarund avatar Sep 22 '22 20:09 aldarund

@aldarund You can use it to do that: https://stackblitz.com/edit/github-s9qt7x?file=pages%2Findex.vue. But if you don't want it to be run more than once you will need to ensure a value - any value - is returned.

danielroe avatar Sep 23 '22 15:09 danielroe

@danielroe ye i though about it, not so clean solution but anyway. Btw if in your example return empty string instead of dict - it will break and will be called both client and server https://stackblitz.com/edit/github-s9qt7x-pawc6h?file=pages%2Findex.vue

aldarund avatar Sep 28 '22 15:09 aldarund