Skip to content

Provide clearNuxtState function for useState #21293

@jongmin4943

Description

@jongmin4943

Describe the feature

The useState uses useNuxtApp().payload.state to preserve the value after server-side rendering and share the value across all components through a unique key. If useState is previously used with a key and if the key is the same, it will use the cached value regardless of whether it has a different init method or not. It is useful to use cached data when needed. However, in some cases, the value of useState needs to be redeclared with a new init method. It seems like the only way is creating unique key every time.

It would be nice to have just like clearNuxtData function to clear cached state value, so we don't have to think how to make a unique key when we want to change the value of useState

Additional information

  • Would you be willing to help implement this feature?
  • Could this feature be implemented as a module?

Final checks

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions