Skip to content

Can the initialValue of useForm be populated with a ref? #23

@johnson86tw

Description

@johnson86tw

Describe the feature

Greetings,

I am currently implementing a scenario using this package. In the case of searching for a product by name, I would like to have my reactive URL, reactive form, and reactive API request all share the same ref. The code structure would look something like this:

// Updates the URL synchronously
const { search } = useRouteQuery("search") 

// Validates the input
const { values } = useForm({ 
    initialValues: {
        search: search,
    }
}

// Allows reusability of this composable in other components
const { products, pending, error, refresh } = await useProducts({ 
    params: {
        search: search
    }
})

When designing the useProducts function, I modified the type of useProductsOption.params.search to type MaybeRef<T> = T | Ref<T>, allowing it to accept a ref and share the same set of ref variables. I would like to inquire whether the initialValues of useForm can achieve this functionality.

Perhaps there is a better way to solve my issue of sharing the same ref? I would like to hear your suggestions.

Cheers

Additional information

  • Would you be willing to help implement this feature?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions