DEV Community

Discussion on: Watch for Vuex State changes!

Collapse
 
xgenvn profile image
Brian Ng

Hmm, the usage of 'mounted' hook to fetch API seems to be contrast from what I have read recently.

Are you sure that is the correct place to put API call?

Collapse
 
viniciuskneves profile image
Vinicius Kiatkoski Neves

Hey!

Sorry for the late reply, I was on vacation for a week and attending a conference this week!

Yeah, I definitely agree that you might use it in the created hook, I use it like that most of the time. Nevertheless regarding the examples shown above it won’t have an impact in the logic itself. The big difference is if you want to access the DOM or not, or if you have SSR in place as well which can cause some inconsistencies as created hook runs in the server and mounted doesn’t.

Do you think it would add any value updating the examples?

Thanks!

Collapse
 
xgenvn profile image
Brian Ng

From my previous read, I would love to see we can provide consistent tutorial and samples.
I also use mounted hook to fetch API due to non-SSR requirements. But then I'm working on some Nuxt projects so I need to change my own practice.
If you can update the examples then it'll be perfect. Thank you.

Thread Thread
 
viniciuskneves profile image
Vinicius Kiatkoski Neves

It took a bit longer than what I expected but just updated the repository with the examples. I'm going to update the examples here as well. Thank you again for pointing it out!

Thread Thread
 
viniciuskneves profile image
Vinicius Kiatkoski Neves

It should be all up-to-date now. I've also checked the text itself to update any references to mounted.