The Context lets you store data and access it in different lifecycle hooks.
Sometimes you need to store arbitrary data so you can access it later in your autocomplete. For example, when retrieving hits from Algolia, you may want to reuse the total number of retrieved hits in a template.
Autocomplete lets you store data using its Context API and access it anywhere from the state.
Context exposes a
setContext function, which takes an object and merges it with the existing context. You can then access the context in
The following example stores the number of hits from an Algolia response, making it accessible everywhere in your autocomplete.
Context can be handy when developing Autocomplete plugins. It avoids polluting the global namespace while still being able to pass data around across different lifecycle hooks.
setContext function is accessible on your
It's also provided in:
context object is available on the
(value: Record<string, unknown>) => void
The function to pass data to to store it in the context.
The context to read data from.