Skip to content

refManualReset | reset ref to inital value #4564

@isimehmeti

Description

@isimehmeti

Clear and concise description of the problem

The VueUse library currently provides refAutoReset, which resets a ref’s value to its initial state after a specified timeout. However, there are cases where a manual reset is needed instead of an automatic one.

I propose adding a refManualReset utility that allows resetting a ref to its initial value on demand.

Use Cases

  • Restoring a ref to its default state after an action is completed.
  • Managing UI states that need to be reset programmatically, such as form inputs or temporary status messages.
  • Managing pinia state
  • Avoiding workarounds like storing the initial value separately.

Suggested solution

const foo = refManualReset('bar')

foo.value // Normal getter
foo.reset() // Resets to the initial value ('bar')

Alternative

No response

Additional context

No response

Validations

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions