Set an initial state
Initialize the Autocomplete state with theinitialState
prop.
JavaScript
Listen to state changes
The state changes when users interact with Autocomplete (for example, by updating the search box text or selecting an item). Watch for these changes and respond to them by passing the state object to theonStateChange
lifecycle hook.
JavaScript
Update the state
Update the state with setters. For example, to let users fill the search box with a selected Query Suggestion, usesetQuery
.
When using state setters, call refresh
to update the UI with fresh sources based on the updated state.
Reference
The state object changes as users interact with Autocomplete but you can also change the state with setters.State object
The state object is available in all lifecycle hooks.The active (highlighted) item.
The search input value.
As the query changes, the items retrieved from sources also change.
The completed version of the query.
Whether the Autocomplete display panel is open or not.
The Autocomplete collection of items.
The Autocomplete status.
The global context passed to lifecycle hooks.
For more information, see Context.
Setters
Sets the active (highlighted) item.
null
clears the selection.Sets the query.
Sets whether the Autocomplete display panel is open or not.
Sets Autocomplete status.
Sets the Autcomplete collection of items.