Nuxt · NUXT0061
Use explicit useState keys in exported composables
Finds Nuxt state code that should use the supported explicit usestate key in exported composables pattern instead.
nuxt/state/prefer-explicit-usestate-key-in-exported-composablessrc/rule-packs/nuxt/rules/nuxt/prefer-explicit-use-state-key-in-exported-composables.ts Upstream docs Run this rule
pnpm nuxt doctor --rules nuxt/state/prefer-explicit-usestate-key-in-exported-composables
Why it matters
Compiler-generated useState() keys depend on the composable's source location. An explicit key keeps state identity stable when an exported composable moves or changes.
Recommended fix
Use the Nuxt-supported explicit usestate key in exported composables pattern instead.
Useful links
Example
Use explicit useState keys
Before
export function useCounter() {
return useState(() => 0)
}
After
export function useCounter() {
return useState('counter', () => 0)
}