What is the use of the key property in useFetch composable options (Nuxt3)

Viewed 123

i'm new to nuxt3 and i don't understand the role (use) of key option in useFetch composable

it says ;

/*
key: a unique key to ensure that data fetching can be properly de-duplicated across requests
if not provided, it will be generated based on the url and fetch options
*/

can someone give a simplified idea) thanks in advance

1 Answers

The biggest clue is in comment you posted. The key word is de-duplicate/d

/ (diːˈdjuːplɪˌkeɪt) / verb. (tr) computing to remove (duplicated material) from a system.

So it is used to prevent the data from being fetched more than once between the server and client as part of the Hydration.

I believe but stand to be corrected that when hydrating a server-rendered page the key is used to map the result of the server-side to the client-side component data.

Related