What is the benefit to use useNuxtApp() on Nuxt3?

Viewed 99

I'd like to know about new Nuxt3 feature called useNuxtApp.

Official document says, to use provide, you can do like below.

const nuxtApp = useNuxtApp()
nuxtApp.provide('hello', (name) => `Hello ${name}!`)

console.log(nuxtApp.$hello('name')) // Prints "Hello name!"

However it seems like you can also still use provide/inject.

For instance, I define the method 'hello' on parent component, then I also want to use it on child component, I can provide 'hello' for child from parent component and inject it.

You can still do same things by using provide/inject, so does anyone know what is the benefit using useNuxtApp?? And what is the difference between provide/inject and useNuxtApp except for syntax??

0 Answers
Related